4 ms·
I've gotten to where I see loops as a code smell. That includes thinly-veiled loops like ruby's Enumerable#each.
by joncp 7y ago
I've gotten to where I see loops as a code smell. That includes thinly-veiled loops like ruby's Enumerable#each.
- tom_mellior 7y agoAnd instead you use...?
- krferriter 7y agoYeah I'd like to know also. Loops are a foundational operation. Instead of a loop you could use a function/operator overload, which would just call another function which contains the loop. But that isn't doing away with loops, it is just encapsulating them inside a function and calling them in order to avoid polluting up the higher level code context with loop code, and makes that upper context easier to read.
- wffurr 7y agoYou described the GPs point perfectly. This is also covered in the article; it exhaustively covers the use cases for loops and provides higher level functions and operators instead.
- tom_mellior 7y agoIt covers the use cases for loops over arrays/lists, not over more general graph-like structures.
- wffurr 7y agoFor which there exist a slew of higher order graph traversal algorithms.
- riquito 7y ago> Loops are a foundational operation. Instead of a loop you could use a function/operator overload, which would just call another function which contains the loop That's incorrect, you can always replace a loop with a recursive function (e.g. as you do in Erlang where there aren't explicit loops)