Comments on: Avoid Loops, Use Map() https://v1.bensweedler.com/avoid-loops-use-map/ Tue, 22 Oct 2019 04:20:49 +0000 hourly 1 https://wordpress.org/?v=5.2.4 By: Costumelooks https://v1.bensweedler.com/avoid-loops-use-map/#comment-685 Mon, 07 Oct 2019 20:04:43 +0000 http://v1.bensweedler.com/blog/?p=1033#comment-685 Look at your code again. Spot any places that you wrote a for-loop previously by intuition. Think again and see if it make sense to re-write it without using for-loop.

]]>
By: Phil Parker https://v1.bensweedler.com/avoid-loops-use-map/#comment-644 Mon, 09 Sep 2019 20:24:04 +0000 http://v1.bensweedler.com/blog/?p=1033#comment-644 I’ve been out of the loop of language development for so long that neither foreach nor map are familiar concepts. foreach is so obvious and understandable that I got it instantly from seeing one example. Further, its benefits are immediately obvious. If I refactor my application to use a binary tree for a collection instead of an array, I don’t have to rewrite all my loops!
map, on the other hand, will take some brain rewiring. I haven’t done any sort of functional programming since LISP in college and that has faded, and I daresay that I actually got the hang of LISP more than any of my classmates back then.

I’d suggest that the interest of your code being easily understandable to anyone who might need to see it would recommend using foreach until you have an application that significantly benefits from map, where map expesses something fundamentally different than a simple loop, rather than just expressing the same thing in an arguably better way.

]]>