3 ms·
> Function returning function returning function is an awful style of coding that is hard to read. Although I hate functional options for their lack of discove
by jen20 4y ago
> Function returning function returning function is an awful style of coding that is hard to read.
Although I hate functional options for their lack of discoverability, the idea that currying is "awful" is pretty far fetched.
- munificent 4y agoGiven that the parent comment says "hard to read", an obvious charitable interpretation of their comment implies "with Go's syntax". Currying in languages that use different syntax is orthogonal to the point being made here.
- codedokode 4y agoUsing currying by itself is fine and easy to understand. But if you write a function that returns a function that returns a function — that's not easy. For example, compare these two functions: function (a, b) { return a + b; } function create_adder(a) { return function(b) { return a + b;}} The purpose of first function is easier to understand. And if you rewrite last function according to modern trends, it can become even less readable: const create_adder = (a) => (b) => a + b;
- jen20 4y agoNo-one would actually do this in real code though - this pattern is typically used for partial application.
- xigoi 4y agoHow is (a) => (b) => a+b less readable than (a,b) => a+b?
- codedokode 4y agoBecause the first is a function returning function, and you have to think how that works, and the second one is just a simple function that returns a sum. Also, if you start a function with a word 'const' then it is less obvious that this is a function and not just a constant. In contrast, if you use a word 'function', then you understand what it is from the first word.
- xigoi 4y agoThat's only because you're not used to currying. A function is “just” a constant.