washingcode-book icon indicating copy to clipboard operation
washingcode-book copied to clipboard

Loops vs Array Methods?

Open r002 opened this issue 3 years ago • 1 comments

Hi! Thank you for writing this book! 🙏 I consider myself an intermediate programmer but there's always so much to learn! Am glad to stumble across your writings! (Someone I follow starred your repo! 😀).

I've been reading: https://github.com/sapegin/washingcode-book/blob/master/manuscript/Avoid_loops.md

and see that you're a big fan for map and filter. I remember when I first learned about these functions, they seemed incredibly spiffy too. 🚀

But this past year I've been recently diving into other languages though and there are other well-known/famous programmers like Guido in Python who discourage/strongly dislike map/filter/reduce (famous article) as well as Rob Pike (co-creator of Go) who really hates map/filter/reduce.


Quoting Rob Pike:

image


From your article, I see you dislike reduce (Guido does too!) but with Python, we at least have list comprehensions so I can understand Guido's reasoning. But with Go-- Pike, et al, really went out of their way to completely banish array methods from the entire language (including map and filter).

Is your book only for JavaScript? I guess I'm just confused bc I'm currently learning Go and the language outright bans array methods and ternary operators (which I see you also use a lot).

(Though in the Preface, you say you can apply your ideas to any language though?)

Also: Do you recommend array methods in JS specifically only for JS frontend because the nature of the domain is a good match for it? (Like, if someone is programming in node.js, doing backend work, would you also recommend array methods?)

I guess I'm just trying to get to the root of the reason why different really smart people have such vastly different (and strong!) opinions re functional programming (and constructs/idioms like array methods). Is it simply because their domains are so different? (Ie. Go is for massively distributed, concurrent programming, monolithic industrial-strength/professional grade/unglamorous use cases and JS is for ...more artisanal/beautiful/built-by-the-TC39-committee-and-needs-to-appease-many-stakeholders use cases?)

Or is there more to it? Thank you for sharing your thoughts! 🙏🙏🙏

PS. Btw, if you don't want to clog up your Issues trackers, GitHub now has a Discussions tab that you can enable! 🙂

r002 avatar Apr 19 '21 15:04 r002

Hey Robert! Sorry for the late reply ;-)

What I really dislike is people promoting their opinion as a religion, and I'm really tired of that in the industry :rage1: I try not to be religious in my book and tell about things that work for me, for the kind of work I do (UX, frontend) and tools I use (JavaScript, TypeScript, HTML, CSS, React, a bit of Node.js). But it doesn't mean that this is the only correct way of writing code — there isn't one. If you think array methods make the code you write easier to read, then I guess it's a good idea to use them. Or your language may have better tools to express what you're doing, like the list comprehensions in Python you're mentioning.

I hope I've answered your question at leat a bit ;-)

sapegin avatar Sep 08 '21 12:09 sapegin