DEV Community

loading...

Discussion on: You should write a comment on every line of code

Collapse
jmau111 profile image
Julien Maury

Very nice post.

Some developers find some comments irrelevant. According to them, you should write comments only when necessary. They have a point with comments like that :

// process form
function processForm($form) {}

Pretty useless. It's the same when developers try to explain their patterns :

// here I use encapsulation, I also made a factory.

You should talk about it with your teammates but not write that in code.

However, I like comments like that :

// we did that here because of these external constraints, etc.

or :

// code is hacky, needs refactor

It's especially useful when working with long-term projects and legacy code. It allows understanding why some things might seem weird or why you get a bug in specific parts of the application.

Some comments have been hidden by the post's author - find out more

Forem Open with the Forem app