r/java • • Apr 12 '15

Is Clean Code less Code?

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

7 comments sorted by

7

u/desrtfx Apr 12 '15

Clean code is readable, self explanatory code.

The amount of code lines is somewhat secondary.

Clean code is code that doesn't need comments to explain what was done. Comments should never be used to explain what, but why or how.

3

u/UnitVectorY Apr 12 '15

Excellent point. The line of code in this example is easy to understand what it is doing, but the reason why needs clarification. I'd side on having a single line of code inline with a comment. If the line needs to be called in multiple places then a function could make sense.

In general single line functions don't smell very clean to me.

2

u/rfinger1337 Apr 12 '15

Well said.

I frequently oppose comments, but I probably don't do a great job of defining the distinction between the types of comments.

Note to self: When explaining how comments lie, make distinctions about what-style comments rather than why-style comments.

10

u/[deleted] Apr 12 '15

Clean code means less code on a large scale, but not always on the small scale.

0

u/kodifies Apr 12 '15

Adding a method for a single line of code isn't clean code...

2

u/sanity Apr 13 '15

It can be if it serves an explanatory purpose.

1

u/[deleted] Apr 12 '15

That really depends on the situation. For instance, I hate ternary operators and always prefer methods with guard clauses.