News for hackers. Stuff that matters.
Re:Array Iteration Interview Problem by revelation on Wednesday August 01, 2012 @09:36PM (#4326750)
Performance differences are anything but negligible. In the case of the "billion elements", you are now spending the majority of time for reversing the array twice.

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.

Re:Array Iteration Interview Problem by sanderjd on Wednesday August 01, 2012 @09:45PM (#4326777)
> 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.