DEV Community

Discussion on: TODO in code

Collapse
 
codemouse92 profile image
Jason C. McDonald • Edited

I like to leave TODOs in my code for small issues related directly to a bit of code. There are three good reasons:

1) For line-based issues, the TODO helps prevent "line drift". That is, if you state that you need to optimize the code on lines 32-67 (sometimes the best direction you can give), if you change the file significantly, lines 32-67 may become lines 108-143. The TODO helps anchor you to the location.

2) Other people (and the future version of myself) browsing the code may stumble across something that can be done immediately.

3) I'll try leave a TODO comment listing what I was last working on before putting the code away for the day/week/month, to help me resume work later.

That said, at work, we also follow The Rule Of Tasks:

The Rule of Tasks: If it won't be done in the next 10 minutes, file an task (a.k.a. Issue/Ticket).

Nearly every TODO should have an accompanying issue or ticket. What you don't want happening is your code becoming its own bug tracker! Again, TODO is good for short, code-specific issues, as well as for "I stopped here" reminders. For anything else, I don't recommend them.


P.S. If you're going to use //TODO, you should also hook up your IDE or static analysis tools to detect and display them. Otherwise, you could seriously misplace them (in which case, you might as well have never put the comment in to begin with.) Atom, Code::Blocks, and cpplinter all handle this nicely.