3 ms·
A is objectively more complex: B gives you all the information you need to know what's going on. A requires you to go dig up what "partial" is doing (which, i
by jasonkester 9y ago
A is objectively more complex:
B gives you all the information you need to know what's going on.
A requires you to go dig up what "partial" is doing (which, it turns out is itself doing some wacky gymnastics to turn one of its arguments into a function and the other into a parameter (and the parameter of whatever gets passed into the returned function as the other parameter of the function that was originally passed in).
Observe how much writing it took just to describe what's going on with your "A". No explanation at all is required for B. It's complete as written. Simple, and intuitive all in one.
- beaconstudios 9y agoif you're writing functional code, you should already know what partial application is - and the "partial" function is only necessary in this case because JS isn't a curried language by default. your idea of B being more simple is largely driven by the fact that you likely have more experience writing code in that manner. With experience writing functional code you should find that both A and B are clear at a glance.
- avmich 9y ago"partial" is an independent concept, which could be learned once and applied after that just as "function" can be in example B. You don't say that "function" and "return" are doing some wacky gymnastics in the code do you? It takes a lot to describe what's going on with A because it's a relatively new concept, related to the subject of the article. If partial application would be just as well known as function definition, the explanation could be shorter.
- jasonkester 9y agoBut it's not. "partial" is specifically defined as its own function in the article. If you're a developer coming across this guy's project for the first time, you'll have to dig one level further into the stack before you find it. Only then do you get to learn those unnecessary gymnastics, so you can follow the rest of his code.
- avmich 9y ago"partial" is an idea which is known in programming, specifically functional one, and its use is much wider than this particular example. It's just that JavaScript doesn't have this standard it has to be defined. Similarly a concept of "function" is a widely known one, which you also need to learn. The whole article makes sense as telling something new to the one who doesn't know what's the point-free style is - but might know what the partial application is. It's a feature, not a bug when something is learned as the result of reading the article and can be applied later.
- lmm 9y agoIf "partial" were only usable for this one function you'd be right. But actually it's a very common, general function (under various names); in many languages it's already present in the standard library, or at least in an established library that's commonly used. Fundamentally this is what programming is all about - finding the commonality that you can pull out and reuse, rather than doing every single case by hand.
- moomin 9y agoI think you're confusing the concept of "complex" with "harder for me to process". There are many, many things that are /simple/ that are actually pretty hard to understand. Most of higher maths, for instance.
- savanaly 9y agoA only seems more complex because you're not used to the concepts involved. If you were then it would seem less complex than writing it "longhand".