The Line Between Chaos and Clarity in Code Comments
Image generated with Leonardo.ai

The Line Between Chaos and Clarity in Code Comments


You’ve probably heard it a hundred times: “Comment your code.”

At times, it feels like no matter how many comments you write, it’s never enough. Other times, the code ends up looking more like a novel than a program. So what’s the right balance?

Before we try to answer that, let’s rewind a bit. Because while comments might seem like just developer etiquette, history shows they’ve done far more — from guiding spacecraft to saving lives. And in some cases, the absence of a simple note in the codebase can lead to multi-million dollar failures.

When we talk about the importance of code comments, it’s easy to think of them as developer etiquette — a good practice, not a necessity. However, in mission-critical systems, the presence or absence of a few well-placed lines could mean the difference between success and catastrophe.

Take NASA’s Apollo program. The software that guided the lunar lander had to operate on extremely limited hardware, and while the comments in that code were often quirky or humorous, like the famous “TEMPORARY, I HOPE HOPE HOPE,”.

Fast-forward to 1999, when NASA lost the $327 million Mars Climate Orbiter due to a mismatch in units — one team used imperial(bruh!!), another used metric. The underlying issue wasn’t the math, but the assumption that everyone was aligned. This is more of a communication and documentation issue, but a simple inline comment clarifying the expected units could have prevented the miscommunication and saved the mission.

And then we have the Therac-25, where the dev reused snippets from older systems without a proper review, which caused fatal overdoses for multiple patients.

It's clear that comments are important as in for the one who will work after you and for yourself later when you revisit the code.

Most engineers are not working on software that leaves to interstellar space, but it often powers banking systems, healthcare platforms, or enterprise applications, where bugs may not kill, but can definitely cost.

Personal Experience

Select in LINQ

If you’ve read my other article How Taking Notes Saved My Ass”, you’ll remember how I got stuck debugging an issue, only to discover that LINQ’s Select() method doesn’t preserve order. That realization was frustrating, but it was also a perfect moment to leave a comment in the code. Something that would save the next person (or future me) from repeating the same mistake.

10% code, 90% comments

On the other end of the spectrum, I once reviewed a pull request that had zero comments — no inline notes, no XML docs, and worse, a recursive implementation buried inside business logic. I asked the author to add comments. And they did.

But now the code looked like this:

// This function finds the ancestor owner of the object
public int FindOwner(int x)
{
    // Start recursion
    if (owner.Parent == null)
    {
        // Base case, stop recursion, owner found!
        return 0;
    }
    else
    {
        // Call again to find the parent of the current object
        return FindOwner(owner.Parent);
    }
    // Done
}        

The problem here isn’t just over-commenting — it’s meaningless commenting. Comments like “start recursion” or “base case” restate the obvious. They don’t add value. Worse, they clutter the code and make it harder to read.

Good comments explain why, not what. They highlight non-obvious behavior, edge cases, assumptions, or business rules that the code alone can’t capture. The goal isn’t to narrate each line like a documentary — it’s to provide context where the intent might not be immediately clear.

So, what is good and what is not?

  1. Let the code speak first. Strive for self-documenting code — use clear variable names and structure so the code is intuitive by itself.
  2. Comment on the “why”, not the “what”. The code already shows what is happening. Use comments to explain why it’s done that way, especially for non-obvious decisions.
  3. Avoid stating the obvious. Don’t write comments like int age = 10; // age holds the age. If it’s clear from the code, leave it alone.
  4. Call out quirks and workarounds. If you’ve implemented a workaround, hack, or behavior that isn’t intuitive, make it explicit with a comment.
  5. Delete, don’t comment dead code. If a line isn’t needed, remove it. Version control will remember it if you ever need it back.
  6. Stay consistent.

Always remember: comments are for humans. Write them to help the next person (or future you) understand the intent, context, or quirks,  not just what the code is doing.


Stay Curious. Adios 👋

References

This article was originally written on Medium.

Rakshanaa Visvanathan

Silicon Sorceress - Aiming to build a better future byte by byte 💻

3w

That line really hit home for me too - "Delete, don’t document, dead code." I've learned the hard way that keeping unnecessary lines, even as comments, just clutters the codebase and makes things harder to read and maintain.. Really liked the article ✨

To view or add a comment, sign in

More articles by Hiruthic .S.S

Insights from the community

Others also viewed

Explore topics