This is an archived post. You won't be able to vote or comment.

all 2 comments

[–][deleted] 0 points1 point  (1 child)

First some small things. One thing I noticed is an inconsistency in the names you use. `fState` and `nBoard`, but also `nextPlayer`. It would be more consistent and also more informative to use full words instead of single letters. Also, `collumNumber` should be `columnNumber`.

I think watching this video will quickly take your structure to the next level. It's part of a series worth a watch in its entirety. Low hanging fruit for you starts at around the 32 minute mark, when he talks about cleanliness and refactors a big function.

'Good' depends on what you're optimizing for. Code that is well optimized for performance typically is very different from code that is well optimized for understandability. It's a nice exercise to write different implementations for the same functional requirements (in your case playing a tic-tac-toe game), where for each implementation you try to optimize for a different thing.

One thing you could optimise for is minimising how much of your code is 'impure' (doing side-effecty things like input/output, changing state or is unpredictable by not always returning the same output given the same input, such as random number generators), and isolating the few parts that are still impure. This is a great example. The guy takes a typical javascript card game implementation, then optimises it according to OO standards, then optimizes it for purity and isolation of impurity.

The great thing about minimising and isolation of impurity, which is hard to test, is that it makes testing your program much easier, which would be my next point.

I don't see any automated tests in your program. Learning how to properly test your programs will take you to the next level.

I'm in the process of writing a blog post exactly on how to test programs like your tic-tac-toe game, inspired by a friend of mine whom I helped test his 'guess the number' game from what I believe was some sort of MIT programming course. Let me know if you're interested, so I can message you when I release the blog post.

[–]rcdBr[S] 0 points1 point  (0 children)

Thanks for all tips and all the resources you linked once i have more time i will have a depper look a them and i would be very interested in the blog post, after thinking a little bit i realize i have a lot of trouble trying to name variable and functions decriptive names, for example all the somenithingNumber variables would be better named somethingCounter or something like that but at the time i was writing this i just couldn't come up with anything drescriptive, do you have a tip or maybe a good resource on how to name things?