DEV Community

Discussion on: Comments Are The Only "Code Smell"

Collapse
 
valeriavg profile image
Valeria

I disagree. Comment itself is not a "code smell", its misuse is.

There are situations where leaving a comment is a necessity.
Comments are not meant to describe things, but to clarify certain statements and leave notes, regarding use of certain constructions and tools.

For example :

// typeof null is 'object'
function getType(value){
  if(value === null) return 'null';
  return typeof value;
}

// Limit degrees to [0,360), 360 degrees is 0
const degrees = userInput & 360;

// Due to a bug in 3rd party module we need to perform this check
// [link]
const result = thirdPartyModule.exec(validateValue(value));
Enter fullscreen mode Exit fullscreen mode
Collapse
 
bytebodger profile image
Adam Nathaniel Davis

I'm pretty sure that this is exactly what I described in the article.

Collapse
 
valeriavg profile image
Valeria • Edited

Please forgive me if I misinterpreted your article.
It seemed to me, that your article main idea was "don't use comments unless you're absolutely sure", opposite to "use comments code wisely".