Source Code Makeover: Square Shooter, Part 3

The rest of the code will render this text and blit it to the sidebar. The text_y variable will increment whenever it writes out some text, so that the next bit of text will be below the previous one.

Checking in these changes with the log message, Add UI for timers, modified has_[powerup]() methods to return time left.

End of Square Shooter's makeover

That's all I'll do for now. With the code organized, making new features becomes slightly easier. I'll leave you with one last bit of advice: you might not always have to go back and refactor code. Code doesn't rust if you don't modify it: the Square Shooter game worked perfectly fine without bugs before I made these changes. Refactoring is for the benefit of human programmers, not the computer. Any time you make changes (even improvements) you run the risk of adding new bugs.

You only need to go back and refactor if it will make future changes easier to do. Of course, since code almost always has bugs, you are pretty much guaranteed to need to change it. (The code, as opposed to UI and feature, changes are covered in Part 1 and Part 2.)

Either way, I hope this blog series has given you ideas on how you can write cleaner and more readable code (and what makes code "clean" and "readable".) Keep an eye out for future Source Code Makeover blog posts, and thanks for reading!

Page 3 of 3 | Previous page

3 comments on this post.
  1. Horst JENS:

    Al, i love your python code makeovers very much. Less intimidating than looking at a stranger’s code on github and highly instructive. Please continue !

    -Horst

  2. Jasper:

    Thanks for this Source code makeover series! It is a great read.

  3. Jack:

    Really love your article! And I really like the new version of game. Very sticky!

Leave a comment