Then, in the tests, have a set of sanity check calls to both the original functions and the optimized versions.
If ever they differ, the tests fail.
What do you think?
The way I work is I do any changes on the 'simple' code and only once I have something that works correctly do I try to update the 'efficiency' code. I have found if I try to change the 'efficiency' code directly then after a couple of small changes (or even one) I introduce some nasty bug. The basic approach I take is simple and working first and then any optimization second.
Obviously, the answer to this question will depend on a whole bunch of different factors. If given the choice, I would personally choose code readability and simplicity over efficiency.
Depends what you mean by "correctness" and how you determine it. In a perfect world the correct way to do something is the same thing as doing it in the most readable and simple way possible.
If you are asking if I think you should give up readability and simplicity if the appropriate standard requires it, then yes. You should probably implement and follow the standard even if the standard is shit (looking at you DOM).
> Sometimes efficiency is a requirement.
Absolutely, which is why I prefaced my opinion with:
>"Obviously, the answer to this question will depend on a whole bunch of different factors."
If you are writing performance critical code, then simplicity and readability will sometimes (probably) have to take a back seat.
It really depends on the project, but sometimes efficiency is important and when it is having a guide to what the code is trying to achieve in a clear and simple form is really helpful.