Hi everone, I’ve spent a couple of hours coming up with a script for a TicTacToe game and would really love to read your comments or critiques about it hopping that I can learn from your feedback.
If you have the time to look at it, here is is so please download it, play it and let me know your thoughts and comments, would like to know if what you see in it is ‘best practice’ or what would you recommend as best practices that I can implement in there. Thank you
Let me be more specific about things that I would like to have some feedback about ‘best practices’ VS what I coded:
Global variables should be avoided, right? I read in another book that we should probably share variables as parameters between functions. Said that,
– should I refactor my ‘played_choices’ for not being global?
– some functions already have about 3 params, wouldn’t I be abusing on number of parameters a function should have?
– am I making overall well usage of my functions?
I just noticed that I should refactor not to use a function called ‘user turn’ and just call ‘play_it’ directly instead. This is the case:
‘who_first’ function only takes cares of asking the user who plays well. Is it ok? It there a better way to achieve that?
‘x_or_o’ function only takes cares of asking the user if they want to play with the ‘X’ or ‘O’. Is it ok? It there a better way to achieve that?
Last lines of the program is just a ‘while true’ loop that makes the ‘user’ or ‘computer’ play first, if you notice the code in the ‘if’ and ‘elif’ is the same just changing the order that functions are called. Is this correct or is this supposed to be coded in a better way?
If I may be so bold to mention this game is simple and fun.
That said, the code looks clear and obvious at first glance but surely adding a few comments next to each would have been a good idea in to build the practice of good documentation for larger projects.
Even a simple #this prints out the board each turn.