Hacker News new | ask | show | jobs
by agentultra 5227 days ago
Reading poorly written English is hard. When the author can't keep their focus and weave together the structure of several disparate arguments into a cohesive essay, it can be very difficult to understand their intentions. It can be near impossible to follow them to their conclusion and decide what it is they're getting at if they muddy the waters with poor writing.

The same is true of software. Well written software is a joy to read and expresses an idea clearly. I love reading code like this. I love writing it even more.

If we want to write code that is easy to understand we should spend more time reading code than simply writing it all the time. Practice makes perfect but introspection reveals the path to self improvement. Absorbing the good ideas of others and filtering out the bad is part of being a good writer and is especially important to the programmer. Read more code!

1 comments

The problem is that everyone has a different idea of what's nice to read. Some people are more comfortable with an algorithm in a for loop, while others would prefer to write it recursively. Who's to say which is objectively nicer to read?
> "Who's to say which is objectively nicer to read?"

The one that's written clearly. An ugly, obfuscated loop is worse than clearly-written and commented recursion and vice-versa.

If the most pressing readability concern in your code is whether an existing loop would be more easily-read as recursion, you're already done. The code is clean enough. Move on.

Relativism has to be relativised. Some logic is better expressed in a loop, some other fits better in a recursion. A guideline is to use the simplest correct path, which means for example that if complexity of the result is similar, the loop is preferable.