Old code = Blech!

To gear up or some more challenging tasks, I've been writing specs for Rect. If there's anything to inspire humility in a programmer, it's looking over his own code from 4 years ago. Frankly, Rect is completely embarrassing to look at now.

Rect was one of the first classes I wrote for Rubygame, back in 2004, and aside from a few tweaks, it has remained mostly unchanged since then. Looking over the code now, it's obvious that the "stability" (read: stagnation) of the code is more a testament to my own laziness than to the code's "timeless perfection".

Heck, most of this stuff has no tests at all. I found out just now that Rect#collide_hash and Rect#collide_hash_all have been broken since even before Rubygame 1.0! Somehow, no one noticed that I had typed "collide_rect?+( ... )" instead of "collide_rect?( ... )", which leads me to two conclusions:

  1. Ruby doesn't like it when you throw in random plus signs where they don't belong.
  2. No one has ever used those two functions in Rubygame's entire history (or at least never told me they were broken).

Of course, neither of these findings is particularly surprising.


Ash submitted a comment on #

I have that exact reaction every time I get around to working on a project again. Then I spend a good night or two refactoring the living daylights out of it.

Specs are a great way to unearth this kind of thing, by the way. Does RSpec include a code coverage tool?

Have something interesting to add to the discussion? Email your thoughtful comments to comments@rubygame.org.