The comment that just said sorry Bex Calder

programmingcraftcode

The comment that just said sorry

The best line of documentation I ever inherited was a single honest word, and it taught me what comments are actually for.

by Bex Calder 3 minute read

The best comment I have ever found in somebody else's code was a single word. I had inherited a program that did something important and did it in a way nobody could quite explain, and I was three days into reading it before I reached the function at the centre of everything. It was forty lines long, it had no name worth the word, and directly above it, on its own line, someone had written: sorry.

That was the whole comment. Sorry.

I have thought about that comment for years. At first I laughed, the tired laugh of a person who has just realised the next fortnight is spoken for. Then, slowly, I came to respect it more than any of the neat, professional comments in the rest of the file. Because it was true. The person who wrote that function knew exactly what they had done. They knew it was ugly. They knew that some later reader, quite possibly them, quite possibly me, would arrive at this spot tired and confused and in need of one honest human signal, and they had left one. Sorry. It meant: I know. I ran out of time, or out of understanding, or out of the particular kind of energy it takes to make a hard thing simple, and I could not fix it before I had to move on. Watch your step.

Most comments lie a little. They describe what the code was meant to do on the day it was written, and then the code changes and the comment does not, and six months later the comment is a small confident falsehood sitting above a line that now does something else entirely. A comment that says sorry cannot go out of date. It is not a claim about the code. It is a message from one person to another, across time, and its content is simply: this was hard, and I saw you coming.

I deleted the function in the end. I usually do. I read it enough times to understand the one decision that had made it so difficult to change, found that the decision had been forced by a problem that no longer existed, and replaced forty lines with about twelve that a stranger could follow on a bad morning. The sorry went with it. I felt a small pang doing that, as though I were painting over a name scratched into a wall.

So I left one of my own, further up, where the tricky part had moved to. Not sorry, because I was not sorry, I had done my honest best with it. I wrote instead: this is the awkward bit, and here is why it has to be awkward, and here is the thing you will be tempted to do to tidy it up, and here is why that will break. Longer than sorry. Doing the same job. Talking to the person who inherits this, who is probably you, in six months, tired, on a bad morning, needing one true signal from someone who stood here before you.

That is what a comment is for. Not to explain the code. The code explains the code. A comment is there to explain the human.

More from the journal

All of the journal Every piece, by month

More by Bex Calder

On the same subject

Discussion

House rules

  • Sign how you like, but be one person. You may use the name on your account, a name of your own choosing, or none at all. What you may not do is wear somebody else's: no pen name of ours, no member's name but your own, and nothing that reads as the studio or its staff.
  • Argue with the point, not the person. Robust disagreement is welcome; contempt is not.
  • Nothing unlawful, hateful or harassing, nothing that identifies a private individual, and no advertising.
  • Post only what is yours to post. That includes other people's writing and private correspondence.
  • We may hide a remark, remove it, or close an account to the discussions, and we may do so without notice.

What a chosen name is and is not

A chosen name hides you from the room, not from us. Every remark stays linked to the account that wrote it, and the studio can see that link whenever it needs to. Please treat it as a way to speak freely, not as a way to say something you would not put your name to.

Where responsibility sits

Remarks in this thread are written by members and published without prior review. They are the views of the people who wrote them and not those of eQuill Studio. We do not verify their accuracy, and we accept no liability for them or for any decision taken in reliance on them.

If something here breaks these rules or infringes your rights, report it and we will look at it promptly.

This thread belongs to this piece alone. Members choose how they are signed, and can change it from the box below. When the studio or the writer joins in, the page says so with a badge, so you always know who is talking.

OPENING THE THREAD…