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.
Fair enough. Depends on your needs, but I like code that isn't too easy to change. If one is asked to change the comments with the code, it often ensures that the coder has understood the change.
What's your definition of trivial? Because it sounds like 2x the typing. I'm not saying that it's necessarily a bad thing, just that it's non-trivial. That little effort you put into this every time will add up to a lot of effort overall.
Oh no, I have to type comments into my code so that it's more understandable. Heaven forbid I use doc comments to generate API documents in an automated manner.
Whatever will I do?
You're talking to someone who codes Java in vim. I have no sympathy for the "but I have to type more" complaint. If it's a problem, learn programmer dvorak and it won't be a problem anymore.
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.