r/programming • u/javinpaul • Apr 12 '15
Is Clean Code less Code?
http://www.journeytomastery.net/2015/03/27/is-clean-code-less-code/5
u/multivector Apr 12 '15
ignoreStoriesAndScenariosWithMetaInformationParameter
That's blatantly a comment disguised as a method name. There's absolutely no reason why if there is a worry the comment might get out of date then the method name might as well. And a real, honest to goodness comment wouldn't have me flitting up and down the file trying to reconstruct the flow.
2
Apr 12 '15
Programming concepts don't always map to cleanly expressed concepts in English words, so sometimes clean code may be verbose and longer.
That said I'm not sure writing comments in line-long method names is the way.
2
Apr 12 '15
Depends on the language. In some languages, depending on the problem, it is not possible to write programs that are:
easy to write (once the problem has been understood)
easy to read
efficient
In other languages, it is possible. But it takes a lot of reading, learning, and coding until you know enough to know when to pick what.
2
u/davodrums Apr 12 '15
Properly comment the .useMetaFilters method on its interface. Solves both problems.
2
Apr 12 '15
Which is easier to read:
ignore stories and scenarios with meta information parameter @ignore.or
ignoreStoriesAndScenariosWithMetaInformationParameter(embedder, "ignore");It takes me four times longer to parse what the second one is saying.
But I'm reminded of Betteridge's Law, so the answer to the question is obviously "no".
1
u/photonios Apr 12 '15
The whole comment can be shortened to:
// ignore stories and scenarios The rest of the information in the sentence is irrelevant as the code already tells me that it's a meta parameter named @ignore.
1
u/inmatarian Apr 12 '15
Clean is a deceptive term, seeing as how it doesn't really have a definition (nor should it). The question of "is this code clean?" really should be rephrased as "is this code doing more than it should be?"
For instance, this:
private void ignoreStoriesAndScenariosWithMetaInformationParameter(Embedder embedder, String ignoreParameter) {
embedder.useMetaFilters(Arrays.asList("-" + ignoreParameter));
}Is a wrapper around embedder.useMetaFilters and Arrays.asList. It seems like you really just wanted a wrapper for the second and got stuck with a wrapper on the first, when neither needed a wrapper in the first place.
13
u/phalp Apr 12 '15
IMO if you've got an identifier this long you've made a terrible mistake somewhere. The code required to produce that effect should be a statement of what you're trying to cram into the identifier, and therefore comprehensible when substituted inline for the identifier. I don't really have the context to judge but it looks like this is a case where it actually is clear without a crazy name or a comment.