Chad Austin's 10 Pitfalls of Dirty Code

tung's picture

I recently bumped into a programming-related blog entry by Chad Austin, father of Sphere and a member of the IMVU team. Entitled 10 Pitfalls of Dirty Code, it first lists the ways code can turn sour:

  • unclear or too many responsibilities,
  • overly complicated or obscure control flow,
  • concepts that don't map to the domain,
  • too many dependencies,
  • global state,
  • or duplicated logic.

Then he goes on to list how bad code can bite you back:

  1. Dirty code does not scale to larger teams.
  2. Dirty code reduces team morale.
  3. Dirty code makes programmers slower.
  4. Dirty code inhibits the formation of ownership culture.
  5. If product concepts are not reflected in code, programmers might implement features in ways that don't make sense in the product.
  6. Dirty code incentivizes the business to invest in tangential revenue work rather than attacking core business problems.
  7. Even with good automated test coverage, dirty code increases the risk of introducing regressions.
  8. Wide or unclear dependencies reduce the quality of tests.
  9. Dirty code hides real bugs.
  10. Dirty code gets dirtier.

Emphasis mine. If you don't take measures to keep your programs clean, they will get worse. All on their own. It will rot, and it will drag you down with it. If you don't, your code will succumb to the broken windows theory, as Paul Graham writes:

It's pretty clear now that the broken windows theory applies to community sites as well. The theory is that minor forms of bad behavior encourage worse ones: that a neighborhood with lots of graffiti and broken windows becomes one where robberies occur. I was living in New York when Giuliani introduced the reforms that made the broken windows theory famous, and the transformation was miraculous. And I was a Reddit user when the opposite happened there, and the transformation was equally dramatic.

Your code may not seem much like a community anything, but the principles apply all the same.

Code yearns to become rigid. It kicks and screams to stay the way it is, all the time. That rigidity is your enemy. Don't be afraid to break stuff. If you don't change your code, it'll turn bad, and it's all downhill from there.

It's your code, folks: keep it clean.