Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.



Strongly agree!

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.


On point 2, I think it's very possible to write clever, readable code.

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


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.


> On point 2, I think it's very possible to write clever, readable code.

Of course its possible. People can shift gears in manual transmission without clutch by revv matching, but its not for everyday use.


> Don't write clever code, write readable code.

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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: