back

The joy of not programming by coincidence

Today I was going through some old rails code and discovered the joy of not programming by coincidence. I try to leave code better than it was when I found it, which in Rails sometimes means that when I have to touch a controller or a model, i’ll go through the entire class and clean things up / make sure things are tested.

Today, as I was doing this, I noticed tons of code that just didn’t matter. Either it would never be called, or it just had no effect at all.

This reminded me of when I was first learning CSS.

The first stylesheet I ever really had to work with had 20-30+ line id/class style lists. There were random “display: block” or “position: relative” styles hanging out everywhere. When I had to restyle things, the long styles pissed me off, so I just loaded all the browsers and deleted things, checking to see if it had any effect.

This turned into a nice practice, b/c whenever I wrote css, I would only use the styles that were actually relevant.

With Rails, since I now understand how it works much more, it’s so nice to be able to go through methods and turn 10 line methods into 2 line methods simply by cutting code that doesn’t do anything.

February 26, 2009