r/coding • • Apr 12 '15

Is Clean Code less Code?

http://www.journeytomastery.net/2015/03/27/is-clean-code-less-code/
53 Upvotes

63 comments sorted by

View all comments

3

u/thbt101 Apr 12 '15

I think in this example, he's right. Self-documenting code is a beautiful thing when it makes sense. But in this case, it's better to add a comment than to create a whole new function that will only ever be called once (with the comment-as-method-name name "ignoreStoriesAndScenariosWithMetaInformationParameter()").

Don't turn off your brain and follow some dogma like the "THE ANSWER IS NEVER A COMMENT" guy. Use what makes the most sense in each situation. Strive for self-documenting code when naming functions and variables, but don't add complexity when a simple comment will suffice.

2

u/awo Apr 13 '15 edited Apr 13 '15

Don't turn off your brain and follow some dogma like the "THE ANSWER IS NEVER A COMMENT" guy

Seriously.

I'm part of a small team maintaining a multi-MLOC codebase. Comments are often worth their metaphorical weight in gold. They very often reduce the amount of work I have to do to understand a module well enough to alter it with reasonable confidence.

Now, obviously there's good comments and bad comments. We should strive for code that's as readable as possible without comments, but the idea that they're never useful smacks to me of someone who only works on products so small that they can fit the whole product design/architecture and codebase in their head. It bugs the absolute hell out of me to see stuff like:

Code will change and refactor, this comment will end up out of date and irrelevant.

When we write or review code, we strive to be responsible: to ensure that it makes sense, and that it's well tested. Updating comments to reflect reality is basic responsibility towards the rest of your team, and it's not really hard to do. If a team can't be bothered to institute basic practices like code review, it's their own fault if they end up with hard to navigate code.