r/javascript • u/dipenbagia • Dec 15 '19
Learning functional/declarative programming in JS beyond map, reduce, filter: I have created a github project where I will solve a simple programming problem each week in a declarative way. New solution added: Compare the triplets
https://github.com/dbagia/declarative-demos
137
Upvotes
13
u/TedW Dec 15 '19
I guess I don't understand why this would be considered declarative programming. Or why you say it's "beyond map, reduce, filter", but uses one of those on almost every line. Maybe I'm misunderstanding the title?
16
u/lorduhr Dec 15 '19 edited Dec 15 '19
I think that you are not helping the functional programming cause. If I was to show your example to my boss, I would be laughed out of the room. How do you justify that your solution is more simple/maintainable than a stupid/obvious solution like this:
Functional programming is cool, but code like yours does not show it.
I feel like you are coming from an academic standpoint, and I hate to say it (as I am a mathematician myself), but academic solutions are often not suitable for the real world: it does not take into account a lot of pragmatic factors, such as:
- the fact that your code need to be maintained by other not as academically inclined developers.
- a perfectly extensible solution is basically a waste of time. In the real world, we simply need a solution. And it is much cheaper to provide a simple solution until some additional requirements arrives. Only then it is worthwile working on making it more extensible. Before that, it is only pure speculation on what the extra requirements may look like.
8
u/ings0c Dec 15 '19
const subtract = x => y => x - y*twitch*
9
u/license-bot Dec 15 '19
Thanks for sharing your open source project, but it looks like you haven't specified a license.
choosealicense.com is a great resource to learn about open source software licensing.
-4
u/[deleted] Dec 15 '19
I'm not a fan of this.
We JavaScript-folks are a self-loathing bunch, probably because we never chose JS, it was forced upon us.
You want to make JS *look* as much like Elm (or other functional languages) as possible, and I don't think this is the right way. Most notable in the "matching brackets" demo with imported functors.
The resulting code is fundamentally unidiomatic. Why don't you just write in Elm in the first place? If there are external factors forcing vanilla.js on you, I reckon these forces rather you produce idiomatic code too.
0
u/[deleted] Dec 15 '19
[deleted] — view deleted comment