alexsaezm

Álex Sáez

Posted on November 17, 2022

To Do

I love TODO comments. And also FIXME comments. Well, I love any piece of non-code text that helps me with my tasks.
I know some people consider them smelly, and you must never use them or, at least, commit them.
I encountered many teachers at my university who always tell this to the students. And I think it is awful advice.

As far as I know, there are two main motivations against TODO comments.

  • First, you should track these kinds of things in a bug or issue tracker.
  • Second, if you collaborate with multiple users, and everybody uses TODO comments, they lose all of the significance because you can't track what is yours and what is not.

The first is a little more tricky to answer, and I can understand the sentiment, but only some things are worth the time, and some of the projects behave differently.
Generally, a FIXME or a TODO is usually smaller than a real issue or bug. A genuine issue should be tracked in a proper tool that allows a conversation among the developers at least. If it's a small thing like "I need to check this later", use a TODO comment. Apart from that, they are totally ok if you are working on a pull request. You can remove them later if they are not meaningful.

The second is true. But not using comments is not the solution. The solution is to make them right! I'm going to tell you the most simple and stupid thing I added to my workflow in the last months (I think I've been doing this for a year now).

Instead of doing something like this:

func hello() {
    // TODO I need to change the text later
    fmt.Println("Hello world!")
}
Enter fullscreen mode Exit fullscreen mode

Try using your username in the control version system, in my case:

func hello() {
    // TODO(alexsaezm) I need to change the text later
    fmt.Println("Hello world!")
}
Enter fullscreen mode Exit fullscreen mode

And then, here's the trick. A lot of IDE and editors allow filtering comments based on regular expressions!

In my case, I mostly use Goland nowadays, but it works in all JetBrains products.

Go to the TODO tab, click on the filter icon, and select Edit filters:

Go to the TODO tab

Then, add something like this:

My TODO filters

And enjoy your useful comments!

💖 💪 🙅 🚩
alexsaezm
Álex Sáez

Posted on November 17, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

To Do
jetbrains To Do

November 17, 2022