DEV Community

Cover image for How not to ruin your code with comments

How not to ruin your code with comments

Pawel Kadluczka on February 02, 2024

The road to the programmer’s hell is paved with code comments Many developers (and their managers) think that comments improve their code. I disag...
Collapse
 
pgradot profile image
Pierre Gradot

Good comments are even more difficult than good code

I used to write a lot of TODO / FIXME. When I realized that some of them were reaching 5 years old, I decided it was time to stop this technique. Now, when I see a TODO/FIXME I added that is more than one year old, I delete it .

One thought about "Comments linking to tasks/tickets". I believe that a comment just linking a ticket is not useful. On the contrary, I do believe that good comment ending with "for more details, see [JIRA ticket link]" can be interesting. If the link breaks, the comment is still useful. And as long as JIRA is up, the comment is kept relatively short.

Collapse
 
moozzyk profile image
Pawel Kadluczka

If a JIRA ticket contains useful information then linking to it could be useful. I prefer linking to such tickets from commit messages but I admit it is less discoverable. If I decided to do it from the code I would provide a little context in the comment explaining why the reader needs to pay attention and copied the ticket # where they could find more details.

Collapse
 
pgradot profile image
Pierre Gradot

On my previous company (where we used Redmine and then Jira), we had configured our SVN (yes, sorry) to force commit message to start with a code that matches Redmine/JIRA ticket. Hence, all commits had links to tickets.

Thread Thread
 
moozzyk profile image
Pawel Kadluczka

Wouldn't you then have to create meaningless tickets just to fulfill this requirement? I worked in a place that had a similar requirement and finding any useful information in tasks was difficult because the vast majority of them were basically empty and only contained the same title as the commit.

Thread Thread
 
pgradot profile image
Pierre Gradot • Edited

No, they were real tickets from the backlog. Some of them weren't really well written or very complete, but they described real bugs or requests for users.

Of course, some commits weren't linked to backlog items (typos, technical improvements, minor refactoring...)