DEV Community

Cover image for Code Smell 148 - ToDos
Maxi Contieri
Maxi Contieri

Posted on • Originally published at maximilianocontieri.com

3 1

Code Smell 148 - ToDos

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

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
    }      

}
Enter fullscreen mode Exit fullscreen mode

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;
    }      

}
Enter fullscreen mode Exit fullscreen mode

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.

SurveyJS custom survey software

JavaScript UI Libraries for Surveys and Forms

SurveyJS lets you build a JSON-based form management system that integrates with any backend, giving you full control over your data and no user limits. Includes support for custom question types, skip logic, integrated CCS editor, PDF export, real-time analytics & more.

Learn more

Top comments (0)

Cloudinary image

Video API: manage, encode, and optimize for any device, channel or network condition. Deliver branded video experiences in minutes and get deep engagement insights.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay