DEV Community

Discussion on: Thinking of the next developer

Collapse
 
nimmo profile image
Nimmo • Edited

Personally, I advocate coding your comments wherever possible. For example:

if (flights.length === 2) {
  // this is a return journey
  doSomeStuff()
...

should (IMO) be

const returnJourney = flights.length === 2

if (returnJourney) {
  doSomeStuff()
...

The only time comments are really appropriate (again, IMO) is for explaining why something's happening which you think is "a bit weird", which in my experience, is down to weird business logic basically 100% of the time. In those situations, yes, do write a comment. But definitely default to trying to code any comments you can!