DEV Community

Discussion on: 7 Tips For Clean Code

Collapse
 
benstigsen profile image
Benjamin Stigsen

While I do agree that comments are very useful, I do not consider it to be one of the best examples:

// Created a constant variable "foo" and assigned a value of "bar"
const foo = "bar";
Enter fullscreen mode Exit fullscreen mode

Here it is describing what is happening which is quite self-explanatory. I think it would be more useful to describe why the variable is created by describing how it's going to be used.

// Variable "foo" to get details from the user "baz" later
const foo = "bar";
Enter fullscreen mode Exit fullscreen mode

Or something like that.

Collapse
 
akashshyam profile image
Akash Shyam

The piece of code you gave consists of "How to not comment code"... TLDR; don't comment every line of code, comment for specific code blocks can't be understood with just the function/variable names.

Collapse
 
benstigsen profile image
Benjamin Stigsen

Woops, my bad, yeah then we have the same opinion on that.
I didn't see the "not" in:

I'm going to tell you what not to do