Originally posted by: degibson
Originally posted by: chronodekar
What matters is that the next ####### who has to work on your code should be able to get started within less than an hour. (or at least, very quickly)
I hate unreadable code as much as the next person. But in general, readable != efficient. They're not mutually exclusive, but they're not automatically the same thing. Ideally, good code is readable and efficient.
Since we've been down the 'what is readable' path before, and the 'code for the weakest coder' path too, I'll just throw in my ad-hoc, subjective definition of efficient code and call it a day.
Efficient code is not wasteful. It does not waste instruction memory with
needless bloat, data memory with
needless overhead, CPU with
needless computation, etc.. Note the strong emphasis on
needless. That is: big, slow, ugly code can still be efficient if its big-ness, slow-ness, and uglyness are
needed to get the job done.
I know I'm opening a can of worms by saying this... but ... efficiency and readability are sometimes at odds. E.g., A recursive tree traversal is more readable but less efficient than a loop-based traversal. Three nested for loops for a bubble sort is more readable but less efficient than, say, a radix sort. Etc. There are many examples.