Let’s consider this easy-to-read code:
It’s easy to see what’s going on there. But how fast is it in case of
someArray containing 1000, 10.000 or even 100.000 elements? And how does it compare to the following code doing the very same thing?
Both implementations achieve the same result. But the latter does it very fast. And yes, the latter code suffers from readability thus resulting in hardened maintenance of code. But that’s what (proper) unit tests are meant to support.
Using iterators and callbacks same search took several minutes to complete.
In the end the optimum should depend on the actual impact on performance: code running just a few times on boot might use iterators whereas code involved in processing every request to process lists should stick with a more complex, faster approach.
Speaking of callbacks and performance this brings us to another concept of Hitchy.