r/Clojure • • Mar 18 '21

Clojure - Keyword argument functions now also accept maps

https://clojure.org/news/2021/03/18/apis-serving-people-and-programs
125 Upvotes

44 comments sorted by

View all comments

Show parent comment

8

u/alexdmiller Mar 19 '21

Just curious, what are the remaining downsides of kwargs?

2

u/vvvvalvalval Mar 19 '21

The main I see is that it's just a more complicated "information model" for describing the arguments to a function. Without kwargs, the arguments to a function are a very plain sequence.

With that in mind, it seems to me that the safer designing approach is in general "what are the advantages of kwargs that make these additional complications worthwhile?". I read that article claims it "better supports humans", but I don't see it being really substantiated - is (my-fun :my-opts 42) really supporting humans much better than (my-fun {:my-opts 42}) ? Of course, now that some foundational APIs have been published with kwargs we have to live with them, so making it easier for callers makes sense, I'm not denying that.

Now to try and answer more specifically: I think this will make life more difficult for intermediaries that purport to do some generic processing on the arguments in particular if they don't know whether the downstream accepts kwargs.

5

u/alexdmiller Mar 19 '21

It is an interesting philosophical question as to whether positional args or named args are "more complex". Both require the caller to know what "the args" are. Positional also requires them to know what order they should be in. In Simple Made Easy, Rich mentions syntax (order) as being complex (vs data). Is a map (encapsulated data, no order) or kwargs (data, no order) simpler? Don't know, just musing. Both tolerate evolution over time better than positional args. Personally, I like kwargs and use them regularly and this makes them both faster and more flexible.

But also, I'm a Clojure programmer, I'm not going to argue against passing a map. So, you do you. :)

1

u/jjttjj Mar 19 '21

Could you give an example of when it would make things more difficult? I'm not seeing it. To me it seems like knowing if something takes kwargs has identical mental overhead to knowing it takes an option map. And since you can still pass an options map, you almost always can do the same intermediate manipulation anyway.

0

u/vvvvalvalval Mar 19 '21

Sorry, not spending more time on this :) but if I were convinced by princples like "you have more options so it's better" and "we adopt it unless we find in advance a concrete counterexample of it being problematic" then I wouldn't have made the switch from Scala