Some people mentioned they thought the code was messy. Casey addressed that on the stream of day 45 (at 32:30). Essentially, he said that the code we write is to understand how we want to structure the program, and so that "cleaning it up" would be premature "optimization" (wasting time). He also said that "clean code" means:
- easy to find bugs in
- easy to read and understand
- easy to reuse (in the places where it actually needs to be reused)
And also that the "cleanness" of the code should be evaluated according to those objectives, and not to a set of fixed principles.
I couldn't agree more. However, there is a change which I feel would be beneficial: more comments.
Being in Europe, I always watch the YouTube videos. But before, I pull the new code and commit it to a local git repository. Then I look at the code changes that are going to be introduced to get a sense of what is going to be done. Sometimes I can tell what the purpose of the changes is, but very often, I can't.
Similarly, when we revisit or expand on old code, I very often can't remember what it did, and reading it only gives limited insight.
A few terse comments stating the intent of some sections of the code would help immensely. Likewise, a few comment explaining some variables could help as well.
Comments like this (making things up):
| // Compute the distance between the player and the obstacle using Pythagoras' theorem
// dPlayerP will hold the delta between the old and new player position
|
I feel it's also justified since Handmade Hero is a learning project. Comments serve as reminders and help with understanding.
You probably wouldn't do this (in throw-away code!) if you are coding a game on your own. It does make sense in a team however, if it would take more time for your teammates to figure stuff out (or to ask you) than it takes you to write the explanation.
Let me know what you guys (Casey and fellow viewers) think!