Watch out for TODO comments!

Say you have a class with 40-something methods, doing a number of different things… You, as a great software developer, identify that as a bloater smell and wisely conclude that code cries out for a refactoring. Sounds pretty reasonable. Nevertheless, you’re neck deep in work now trying to meet the deadline for the next release. So what you do? You simply leave a TODO comment next to the code for you to perform that change as soon as you have enough time available.

 // TODO: This class is doing too many things. Refactor!
 public class BloatedClass {

    // 40-something methods

}

That’s it! Now you move on with your next task feeling good about yourself because you think you’ve already handled the problem “appropriately”.

“What’s wrong with that?” – you may ask – “after all, I do intend to deal with that later” . Come on, my friend! Let’s be realistic and face the facts! Chances are you’ll forget about that comment and it will remain there forever since neither you nor anyone else on the team will have the guts to carry out that refactoring afterward for fear that something might stop working. This happens because if you remember that comment, you’ll probably already have lost the general context that surrounds that code and thus you may not have enough confidence to refactor. Worse comes to worst when there isn’t a good suite of automated tests to back you up. As a consequence, your fellow workers will have to work and get along with that poor legacy code.

Bottom line: it’s best to try to keep yourself from adding TODO comments to your source code in the first place (in fact, this applies to code comments in general); but, if you do, make sure you don’t forget about them (Eclipse has a “Tasks view”, which can be useful to track those notes). Those comments might be indications of technical debt that you need to be mindful of, yet more often they’ll just be deodorant for poorly written code.

2 thoughts on “Watch out for TODO comments!

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