DEV Community

Discussion on: No Comment(s)?

Collapse
 
kvsm profile image
Kevin Smith 🏴󠁧󠁢󠁳󠁣󠁴󠁿

I think your conclusion (that commenting should be used where code isn't intuitive) is bang on the money - I just think that the cases where it's acceptable for code to be unintuitive are very rare.

At my workplace, for example, comments aren't generally permitted at all. The only case I can think of which would pass code review would be when you have no choice but to do something non-obvious due to a quirk of some external library or system. In all other cases, code with comments would be rejected because:

  • Code which needs comments to be intuitive should be refactored so it doesn't need comments to be intuitive; and
  • Comments can't be tested, so it's hard to know if the message left in one is accurate either at the time it's written or (more importantly) at any point afterwards.

This might seem super rigid, and does feel that way on occasion, but I do believe (and observe in practice with our junior devs) that getting into the mindset of avoiding writing comments does improve code quality over time.

Thread Thread
 
jessicabetts profile image
jessicabetts

Valid!

I think everyone should strive for code that doesn't need explanation! It is interesting how different areas within the programming community feel differently about this. In college, every assignment HAD to have comments. Maybe that was more about making sure we understood what was happening? At coding bootcamp we haven't touched on commenting at all!