DEV Community

Cover image for Getting a comment right
Ross Angus
Ross Angus

Posted on

2

Getting a comment right

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.

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (0)

Some comments may only be visible to logged-in visitors. Sign in to view all comments.

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more