1. Don't blindly follow advice of "experts" you read.
2. Don't write clever code, write readable code. Participate in code golf or obfuscation contests to scratch the itch if you have one, but keep it out of production code, even if its a private project that you will never share with anyone; it will save you from yourself.
I think a lot of the time, we use "clever" to mean "obtuse, unreadable, and/or obfuscated" when talking about code. The positive version of that word is "elegant", I think.
Good one. Clever code is really tempting. It feels cool to do something in one line instead of six and call it a day. In many cases, the mature thing to do is to know how to do the cryptic one-liner, but write the six lines anyway for readability and comment them.
If you write something cool and you're thinking "oh yeah! I am such a Ninja!" then step back and decide whether it needs commenting to explain what it does. If it does need commenting, consider whether you could rewrite it in such a way that comments are unnecessary. Assume your colleagues and future code maintainers are trainee ninjas at best.
Comments (453) 190 threads
Show all comments
Showing thread 34 of 190
2. Don't write clever code, write readable code. Participate in code golf or obfuscation contests to scratch the itch if you have one, but keep it out of production code, even if its a private project that you will never share with anyone; it will save you from yourself.
I think Rob Pike's 5 Rules of Programming[1] are better advice here -- in particular rules 3 through 5.
[1]:https://users.ece.utexas.edu/~adnan/pike.html
Of course its possible. People can shift gears in manual transmission without clutch by revv matching, but its not for everyday use.
Good one. Clever code is really tempting. It feels cool to do something in one line instead of six and call it a day. In many cases, the mature thing to do is to know how to do the cryptic one-liner, but write the six lines anyway for readability and comment them.
If you write something cool and you're thinking "oh yeah! I am such a Ninja!" then step back and decide whether it needs commenting to explain what it does.
If it does need commenting, consider whether you could rewrite it in such a way that comments are unnecessary. Assume your colleagues and future code maintainers are trainee ninjas at best.