Guy Arad
1 min readNov 20, 2016

--

An interesting article and good for quick and brief overview on iteration. However, the recommendation is way too total (get rid of for-loops). Making this effort and forcing it will create unreadable code, to a point that even your future-self will have difficulties understanding the code.

It is a good practice to think about the suggestions here when you write your code. After I’ve written an iteration loop I always try to think how can I make it more readable. At times, even if I can use list-comprehension or an aggregate function (map, reduce, filter etc), I choose to stay with a loop, because that’s how programmers think and will make the code less cryptic.

Make sure your colleagues will understand your code. Go ahead and ask them! This should, anyway, be part of a code review (the reviewers should make sure your code is clear).

Lastly, you should consider efficiency. The method described here are usually more efficient (profile/benchmark your code!) but usually it’s not enough to justify reduced clarity of code.

--

--