Code Smell 148 - ToDos

Photo by Eden Constantino on Unsplash

Code Smell 148 - ToDos

We buy debt for our future selves. It is payback time

Maxi Contieri
·Jul 12, 2022·

2 min read

Subscribe to my newsletter and never miss my upcoming articles

Play this article

Table of contents

  • Problems
  • Solutions
  • Context
  • Sample Code
  • Detection
  • Tags
  • Conclusion
  • More Info
  • Credits

TL;DR: Don't leave TODOs in your code. Fix them!

Problems

  • Technical Debt

  • Readability

  • Lack of Confidence

Solutions

  1. Fix your TODOs

Context

We encounter TODOs in our code. We count them.

We seldom address it

We started owing the technical debt.

Then we pay the debt + the interest.

A few months after, we pay more interest than the original debt.

Sample Code

Wrong

public class Door
{ 
    private Boolean isOpened;

    public Door(boolean isOpened)
    {       
        this.isOpened = isOpened;
    }      

    public void openDoor()
    {
        this.isOpened = true;
    }

    public void closeDoor()
    {
        // TODO: Implement close door and cover it
    }      

}

Right

public class Door
{

    private Boolean isOpened;

    public Door(boolean isOpened)
    {       
        this.isOpened = isOpened;
    }      

    public void openDoor()
    {
        this.isOpened = true;
    }

    public void closeDoor()
    {
        this.isOpened = false;
    }      

}

Detection

[X] Automatic

We can count TODOs.

Tags

  • Technical Debt

Conclusion

We can count TODOs.

Most linters do it.

We need the policy to reduce it.

If we are using TDD, we write the missing code right away.

In this context, TODOs are only valid when doing Depth First development to remember open paths to visit.

More Info

Credits

Photo by Eden Constantino on Unsplash


After you finish the first 90% of a project, you have to finish the other 90%.

Michael Abrash


This article is part of the CodeSmell Series.

 
Share this

Impressum

Technical Opinions are my own. I don't have the revealed truth.

Software Design is a creative activity. These are hints and not rigid rules.

I write on BackEnd Business Systems and OOP Design. My advice/experience might not suit other systems.

You can write me at info(at)maximilianocontieri.com