Day 16: Blackjack Improvements

May 7, 2017

by — Posted in Coding

Since I finished my MVP for Blackjack, I wanted to take some time to figure out ways to improve the base code before moving on to building in more features. 

Improvements I identified:

  • Consolidate player data tracking into one dictionary.  I previously had one dictionary per data type so I could just do ‘player name’: value for the entries, but then I realized it was going to be a pain to make sure I’ve made entries in multiple dictionaries for each player, so I changed my data to be kept in one dictionary such that the value for ‘player name’ is another dictionary containing the data I want to track. 
  • Consistent passing of data from main blackjack function to side functions. Sometimes I passed player name, sometimes I passed player hand, and sometimes something else, which I guess was fine but sometimes hard to remember whether I was passing the right things between functions. I changed them so that I’m always passing player name, and the side functions are pulling data they need from the dictionary. 

I was nervous to make such big changes because I didn’t want to break something I already had working, but I figured…it’s good practice, and if I do it now, the code will be easier to work with moving forward. It surprisingly didn’t take that long to fix – to make the change and fix bugs I introduced took me about 1.5 hours.  Hopefully it indeed makes it easier for expanding moving forward. 

Leave a Reply

Your email address will not be published. Required fields are marked *