4 ms·
More like "how Ruby and Clojure don't really support keyword arguments". Unless you can do something like: >>> def foo(a,b): ... print a,b ...
by kbd 15y ago
More like "how Ruby and Clojure don't really support keyword arguments". Unless you can do something like:
>>> def foo(a,b):
... print a,b
...
>>> foo(b=1,a=2)
2 1
then you don't support keyword arguments, you just have some hack for stuffing parameters into a hash. In fact, MacRuby had to add syntax to Ruby[1] in order to be able to represent Objective C keyword arguments.
[1] http://www.macruby.org/documentation/rubycocoa-to-macruby.html http://www.macruby.org/documentation/rubycocoa-to-macruby.ht...
- cageface 15y agoI find Python inelegant in general but Python's support for keyword arguments strikes the best balance of simplicity and flexibility in any language I've used.
- MostAwesomeDude 15y agoPython's argument conventions are even more flexible; they actually work by passing a tuple of positional arguments and a dictionary of keyword arguments, and unpacking/repacking according to the signature of each function. You can pass any iterable as positional arguments and any mapping as keyword arguments. You can also retrieve the positional and keyword arguments inside a callable as a tuple and dictionary. It's the best calling convention I've ever seen.
- masklinn 15y ago> In fact, MacRuby had to add syntax to Ruby[1] in order to be able to represent Objective C keyword arguments. On the other hand, Objective-C's keyword messages, inherited from Smalltalk, are very different from Python's keyword arguments (to the point that PyObjC can not map one to the other, and uses name mangling for ObjC method calls instead, similar to RubyCocoa's method): in Obj-C, the keywords are part of the method name (in fact, they are the method name) and changing their order or adding new arguments will change the message sent to the object. Not so in Python, C#, or using Ruby's hash-hack, where keyword arguments are basically a `String -> Any` map sent to the method. As a result, even if Ruby implemented "proper" keyword arguments it's quite unlikely unlikely they would match Obj-C's, and MacRuby would still have to implement their own.