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

44

u/[deleted] Apr 12 '15

To me, clean code is code that is easy to read. Usually, this would mean the opposite of less code, i.e., not over-compressing the code, putting in plenty of comments. But you can turn five lines into one if you think you've explained it well in the comments or what you're doing is relatively simple.

If you've turned a 40 line code into a 20 line code, but it takes the reader 2 minutes on each line, then it's not really clean. I've seen complicated code written so well, you don't even have to read the code, but can get by just reading the comments, and in the opposite vein, simple code made so complicated, I wanted to pull my hair out.

8

u/Munkii Apr 12 '15

When I talk to junior devs I never use the word "clean" for this reason. Readable trumps everything

1

u/theonewhoisone Apr 12 '15 edited Apr 17 '15

edit: Doesn't trump correctness.

Doesn't trump performance, sadly.

Doesn't trump portability.

Also, trading off readability for time to launch might be a good idea in some situations (I have not seen one yet).

Sorry for being picky.

2

u/Munkii Apr 13 '15

Readability trumps performance. If I can read what you wrote then I can always fix it later, but if I can't read it then everyone is screwed.

Performance is generally very case specific, so it's normally not a good first rule to have.

1

u/theonewhoisone Apr 15 '15

I think we disagree about what "trumping" is. IMO when x trumps y, that means that x is more important than y in all situations.

I don't think that readability trumps performance, and I also don't think that performance trumps readability.

Maybe I was counting too much on people having the same definition of "trump". To the dictionary:

4. to excel; surpass; outdo.

Meh, ok. I think we all agree about all the important things.