Most upvoted comment
Top rated programming books on Reddit rank no. 28
Is neater/cleaner code any faster?(r/learnprogramming)
People seem to be getting distracted by your first example, which I don’t think describes what you are asking that well.
I’ll have a crack at answering as best as I can. How you layout your code will make very little difference to the efficiency, as it all goes through your compiler and is turned into machine instructions. Your compiler is very, very good at recognising patterns and optimising what you are writing, but the lexical parser will not see a difference between beautiful code and ugly code.
As far as optimising code, understanding data structures and basic algorithm design will improve its speed. A great book for this is The algorithm design manual, which is recommended by Google for their interview process.
Permalink : /r/learnprogramming/comments/1lik4o/is_neatercleaner_code_any_faster/