3 ms·
I always thought currying was a bad idea. It makes the code way less readable: * more difficult to distinguish arguments and return values (there's a reason m
by IshKebab 3y ago
I always thought currying was a bad idea.
It makes the code way less readable:
* more difficult to distinguish arguments and return values (there's a reason most languages have distinct syntax for them)
* it encourages you to put your arguments in an order that might not be the most logical
And on top of that it only works for the last argument(s).
Feels like a lot of disadvantages to allow an overly clever trick that you can do in other languages much more readable using lambda functions. And those work for any arguments, not just the last one(s).
- 082349872349872 3y ago> using lambda functions or (where available) sections
- yen223 3y agoI much prefer partial application. It just makes more intuitive sense - you take a function with many arguments, "fix" some of those arguments, and get a new function out. No need to mess with argument ordering, or all that. It's a shame the only language that did partial application well is, weirdly, Python.
- bPspGiJT8Y 3y agoIn Gleam it also seems to be done well: https://tour.gleam.run/functions/function-captures/ https://tour.gleam.run/functions/function-captures/
- IshKebab 3y agoPartial application just means fixing some arguments. My point was you can do that easily using lambda functions. I guess you were talking about `functools.partial`, which is basically the same as currying and also only works on the last arguments. It's better to use lambda functions. Also Python is far from the only language to have a function like that, e.g. see C++'s `std::bind` which nobody* uses since lambdas were supported. *standard HN disclaimer
- yen223 3y ago> I guess you were talking about `functools.partial`, which is basically the same as currying and also only works on the last arguments I was talking about `functools.partial` yes, but it can work on any arguments in order, using keyword arguments. e.g. def copy(source, dest): ..... copy_to_temp = partial(copy, dest="/tmp/") copy_from_temp = partial(copy, source="/tmp/")
- epolanski 3y agoI can't figure out what you mean. how is `add a b c = a + b + c` being curried an issue to you?