> As a programmer you should always know what kind of cost you are incurring, both asymptotically and down to cycles.
No, as a programmer, you should be able to determine what kind of cost you are incurring when it matters, and much more importantly, you should be able to determine when it matters and when it doesn't.
Re:Array Iteration Interview Problem
by tylermenezes on Saturday August 04, 2012 @06:25AM
(#4338132)
> usually
And even in the case of a billion elements, the difference in time is still negligible. Developer time is almost always better to optimize for. There's a reason Facebook and Google weren't coded entirely in C.
As a programmer you should always know what kind of cost you are incurring, both asymptotically and down to cycles.
Trying to condense all the cases into one (using reverse or local state like 'step' from OPs version) is what hurts readability and maintainability.
Also, the "buy more metal" argument is hardly applicable for implementing this one way or another. Its an argument for using whatever platform you are most productive in.