From: Daniel Schierbeck Date: 2005-10-24T03:17:02+09:00 Subject: Re: A comparison by example of keyword argument styles This is just to get the discussion focused. With named arguments, I'm thinking something along the line of this: An assignment symbol of some sort ("=", ":", "=>", "->", etc.), with a key on the left side and a value on the right side. key: value key = value :key = value key => value key -> value Furthermore, the named arguments are gathered in a hash in which the keys are symbols. keys[:key] -> value We're discussing two things: what assignment symbol to use and what the key should look like (although the latter doesn't seem to be causing much trouble). I'll just go through each of the styles suggested above and pose my thoughts on them. key -> value def foo(a -> "default", **keys) foo(a -> "foobar") con: I don't think we want to add another arrow to the language. No way to specify a named argument without a default value. key => value def foo(a => "default", **keys) foo(a => "foobar") pro: It's what being used at the caller-level already. It looks cool, even when the value's a symbol: foo(a => :b). con: To me, => means "points to", not "is". Therefore it might not be good as an assignment symbol. No way to specify a named argument without a default value. key: value def foo(a:, b: "default", **keys) foo(a: "foobar") pro: Already used in other languages. Intuitive in many cases: obj.move from: NewYork, to: Paris con: Looks silly when the value is a symbol: obj.move from: :newyork, to: :paris mandatory named arguments look silly. :key = value def foo(:a, :b = "default", **keys) foo(:a = "foobar") pro: The key is a symbol, which seems consistent with it being it also in the key hash. Looks cool even when the value is a symbol. con: Looks like you're assigning a value to a symbol. key = value foo(a = "foobar") pro: Looks clean and cool, even when the value is a symbol. con: May be hard to implement. Doesn't specify how you seperate named and positional arguments (maybe use a keyword like "named"?). def foo(a, b = "bar", named c = "default", **keys) Personally I prefer the last version (key = value) with a keyword in front of named arguments. Furthermore, the key: value syntax could be used alongside, where appropriate, on the caller side. def foo(a, b = "bar", named c, named d = "default", **keys) foo(1, "foo", c = 123) foo(1, "foo", c: 123) Just my $.02 Cheers, Daniel