Getting a comment right
Ross Angus

Ross Angus @rossangus

About: The views I express here are mine alone and do not necessarily reflect the views of my employer.

Location:
Edinburgh
Joined:
Mar 12, 2019

Getting a comment right

Publish Date: Aug 20 '20
2 1

I love code comments, and think of them as just enough documentation for the dev at that particular moment. They're also, of course, where you explain yourself to your peers and future self.

Today, I needed to switch a dialogue window from being position: fixed to position: absolute I wasn't quite sure if this would turn out to bite me in the arse or not. So I needed to add an unambiguous comment, for future me (hate that guy) to read. Here's how that went:

.dialog {
  position: absolute; // Was fixed
  top: 50%;
  transform: translate(-50%,-50%);
  width: 90%;
}
Enter fullscreen mode Exit fullscreen mode

Hang on - that's not right. It looks like the element was fixed at some point in the past. I'll try quotation marks:

.dialog {
  position: absolute; // Was "fixed"
  top: 50%;
  transform: translate(-50%,-50%);
  width: 90%;
}
Enter fullscreen mode Exit fullscreen mode

Oh God - that just looks sarcastic. I'll type the whole thing out:

.dialog {
  position: absolute; // Was position: fixed
  top: 50%;
  transform: translate(-50%,-50%);
  width: 90%;
}
Enter fullscreen mode Exit fullscreen mode

That colon could be missed in a skim-read and mistaken for bad English. I'll try quotation marks again:

.dialog {
  position: absolute; // Was "position: fixed"
  top: 50%;
  transform: translate(-50%,-50%);
  width: 90%;
}
Enter fullscreen mode Exit fullscreen mode

That'll do, I guess.

Comments 1 total

Add comment