“Not sure why”

I just saw a comment like this in a piece of code written long ago:

“Do this particular thing because it behaves like this.  Not sure why.”

That, to me, is a code smell.  If you aren’t sure why a particular piece of code is behaving the way it is, it’s best to take the time to understand why it is behaving the way it is, rather than compensating for it in other places.  Compensating for unknown behaviour leads to messy code and unexpected bugs.  It makes maintenance harder, because you then have to update code in more than one place.  Duplicate code = duplicate bugs = more maintenance = it takes you longer to get new features in.

If you aren’t sure why – learn why!  An hour spent now saves ten hours spent later.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s