99% of the time I see usage of Array.prototype.some and Array.prototype.reduce, it would have been much more readable with a manual loop.
-
-
#2 Sets up a pipeline of values through expressions. #1 Does its magic with explicit flow control. IMO, #1 uses implicit side effects, even if the side effects are in flow control, rather than mutating values.
-
How does #2 not use control Flow? It’s hidden in the implementation details of Array.some. Would the usage of Array.forEach somehow make it declarative because it hides the actual logic?
- 5 more replies
New conversation -
-
-
The second one has a function you can factor out, reuse, and test. I might have gone with `every` instead of `some`, personally. But the for loop is more optimized for a lot of cases.
I just use the best tool for the job.Thanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
This is probably inadequate, but IMO it explains “what” you’re asking for, not “how” to determine that. More declarative than imperative, which tends to be a property of functional programming.
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
Philosophically? #2 describes What you Want (it's declarative) and #1 is specific on How To Implement It. The implementation of `some` can be improved (parallelized, whatever), whereas it's harder to systematically improve loop code
-
(I'm not trying to make this argument specifically for this example, more describing the Zen of FP In General)
End of conversation
New conversation -
-
-
B-cause is more declarative than imperative talvez?
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
Because most of the time FP isn't about anything functional at all. It has evolved to be the practice of using the most implicit, least-keystroke-requiring, most difficult to interpret code possible. Duh.
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
I'd say rather than functional, it's more OO since you're sending messages to an object instead of reaching into internals. It lets you replace `whitelist` with any object whose `.some` is a function.
-
#1 is more imperative since it includes an inline implementation of `Array.prototype.some`. This is all coming from a Ruby perspective, though, which eschews traditional `for` loops for method calls to Ruby's `Enumerable` mixin.
End of conversation
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.
he/him 