Tech Debt: Code Todos Never Get Done?
Tags: programming, productivity, discuss, developer
Published: 2024-07-08 11:56:36

Let's talk tech debt and code improvements. We've all been on a development team where ToDo comments are left in the code, hoping they'll be picked up during downtime when no active tickets need attention.

## Table of Contents
[The Downtime Never Comes](#the-downtime-never-comes)
[How It Is Normally Handled](#how-it-is-normally-handled)
    [Tech Debt Tickets](#tech-debt-tickets)
    [ToDo Comments in Code](#todo-comments-in-code)
    [What's the Problem?](#whats-the-problem)
    [There Is a Solution Though!](#there-is-a-solution-though)[Forging a Tech Debt Strategy](#forging-a-tech-debt-strategy)
[There's Tools to Help You!](#theres-tools-to-help-you)
[Benefits Of This System](#benefits-of-this-system)
[Conclusion](#conclusion)


## The Downtime Never Comes

However, downtime never arrives. Product owners constantly demand new features, and developers' worklists keep growing. Tech debt tickets often get lost among other priorities, leaving no time for refactors or ToDo improvements.

## How It Is Normally Handled

In my experience, there are two ways tech debt or coding improvements are handled in a development team:

### Tech Debt Tickets

When a developer identifies an improvement or rogue code, they create a ticket (for this article we'll use JIRA) with instructions/details. 

First, not all developers are skilled in creating JIRA tickets, leading to poorly titled tickets, missing tags, or overly detailed technical descriptions. 

Secondly, these poorly created tickets get lost in a large product backlog. This method only works if tickets are correctly made and tagged as "tech debt" for easy retrieval.

### ToDo Comments in Code (the reason we're here today) 

When developers encounter rogue code unrelated to their current work, they leave a comment like:

`//ToDo: Improve this code for performance - use an object literal.`

These comments are committed to the code base and visible to all future viewers.

**Important:** Avoid refactoring code unrelated to your current work. Mixing changes makes future reverts harder, as commits will include both task-related and unrelated code.

#### What's the Problem?

Many developers complain that tech debt rarely gets addressed because there is no documentation or allocated time in the sprint. These comments are often forgotten until someone stumbles upon them, lost, to only be found by chance.

They never see the light of day and the work is rarely improved, because the team aren't given the time for tech debt, or may not be working in that area of the code base for a while (where the changes requested are relevant to the ticket being worked on). 

#### There Is a Solution Though!

Combine the two methods, adding ToDo comments as you go, using these to power sprint work, let's take a look at this in more detail. 


![Making room in your sprint for tech debt](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fo8oxu87f37gjz87e8vw.png)


## Forging a Tech Debt Strategy

To address ToDo comments, commit to a tech debt strategy. I propose the following solution:

1. Decide within your team how often you'll tackle tech debt, depending on your sprint cycles.

2. Add ToDo comments to the codebase as needed.

3. Before the sprint you've committed to tackling tech debt (based on step 1) review ToDo comments. Pick 3 ToDo comments to address and complete in the Sprint and create detailed tickets for them. This ensures all relevant parties are involved and tickets are well-documented with titles, tags, and necessary technical details.

## There's Tools to Help You!

Many IDE's (Integrated Development Environments) and code editors have plugins or built-in functionality to view `ToDo:` comments.

For example, JetBrains' IDEs view them like this:

![Jetbrains Rider - ToDo viewing functionality](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6k63u1sd3jodjvxpqkq9.png)

As you can see, there are clear details around
- how many todo comments were found
- where they are located (filename and code line)
- the comment left.

If Jetbrains' software is a bit pricey for you, and you're utilising something like VS Code, there's a perfect extension called `ToDo Tree` which is free in the extensions library.

Name: Todo Tree
VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=Gruntfuggly.todo-tree

And displays the results similarly:

![VS Code - ToDo Tree results](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uyt4zijkrgf8imbdmm41.png)

There are many tools, plugins/extensions for many other editors too, so you're not restricted.

## Benefits Of This System

*Easy to add at the time:* - Comments are simple to write and add whilst at that place in the code, creating a virtual bookmark.

*Doesn't break concentration:* - Being able to add the comment there and then whilst you spot it, allows a fire-and-forget approach to the change/improvement. Rather than having to break off, login into JIRA, create a ticket, remember the tags that needed to be added, and fill all the details in, just leave a comment and continue with your thought process. 

Often "code smell" doesn't get recorded because developers don't want to go through the laborious task of creating a ticket when in the middle of a coding flow. 

*Add Prefixes to categorise:* - An approach I've implemented in previous teams, is adding a tag/prefix to your ToDo comments, to help prioritise, or group comments (these would be pre-determined by your team, as not to create repeat or meaningless tags).

Some examples could be:
- High / Medium / Low => priority-based improvements
- "Security" => indicating a security improvement
- "Styling" => improvement around code style
- "Performance" => improve performance, e.g switch case to object literal
- "BP" => best practice e.g. variable naming, code layout, usage of particular functions etc.

Example of how these would be used:

```ts
// Single Tag
//TODO: Performance - update this switch case return, to utilise an object literal lookup`

//Combine tags
//TODO: High, Security - update this function to factor in exposing API secrets
```

Using various tools' filtering ability means sprints can be focussed on tackling particular types of tech debt, or higher priority issues using the pre-determined tags.

## Conclusion

Addressing tech debt and code improvements is a constant challenge for development teams. The traditional methods of handling tech debt, such as creating JIRA tickets or leaving ToDo comments in the code, often fail due to a lack of documentation, prioritization, or effective follow-up. However, combining these methods can create a more efficient strategy, meaning that tech debt is dealt with regularly.

By integrating ToDo comments with a structured approach to tech debt during backlog grooming sessions, teams can ensure these improvements are systematically addressed rather than on an ad-hoc basis. Utilising IDEs' built-in tools or add-on extensions can further streamline this process by providing easy visibility and management of these comments.

Ultimately, a committed tech debt strategy that includes regular review cycles, prioritisation, and commitment to resolving comments can help teams manage their workload more effectively. This approach not only maintains code quality but also ensures that necessary improvements are not overlooked, fostering a more sustainable development process.

As always I'd love to hear your thoughts and opinions on this topic. Feel free to follow for future posts. 

For more tips, discussions, and to hear about other posts I make elsewhere drop me a follow on [Twitter](https://twitter.com/grantdotdev).