Member-only story

15 Rules for Writing Clean Comments

Common pitfalls to avoid as a programmer

Mohammad Faisal
Better Programming
3 min readFeb 12, 2021

--

Magnetic letters scattered on a white background
Photo by Jason Leung on Unsplash

Comments in code have been there since the beginning of programming. But in today’s world, do we need them? Some would argue that we shouldn’t have comments in our code at all.

Well, it’s true. Code should be self-documenting. But still, there are some instances when we need to add comments. About this Uncle Bob says,

“Comments are an unfortunate necessity, not great achievements.”

Today, we’ll look at some rules to follow and the common pitfalls to avoid while programming.

1. Multiline Comment vs. Single-Line Comment

Whenever possible, try to write long comments as multiline comments.

The following comment is bad:

Instead, do this:

--

--

Responses (4)

Write a response