From: Christophe Grandsire Date: 2005-10-21T18:33:32+09:00 Subject: Re: A comparison by example of keyword argument styles Selon Robert Klemme : > > - Mixing both styles for a single method feels not right in Ruby because > it seems more complicated than necessary (just look at the length of the > part of your discussion that deals with this). Stored procedures of RDBMS > can usually be called with parameters given either positional style *or* > keyword style (btw, without a difference in declaration) but not mixed. I > would only allow one of the two approaches. > I'm afraid that would be too restrictive for Ruby. There are already cases (see Rails for instance, as I learned it in another thread) where methods have positional arguments followed by hash arguments, which may be advantagedly replaced with positional arguments followed by keyword arguments. I think it wouldn't fit with Ruby's dynamic argument passing to make positional and keyword styles exclude each other. On the other hand, you are right about one thing: if one is to allow all arguments to be called either positionally or by keyword (the Sydney approach), then the positional and keyword styles *must* exclude each other completely. This is the only way we can prevent confusion. However, I still think keyword arguments should be explicitly defined as such. > - Personally I'd probably favour an approach which allows only one > calling style at a time. Variables that have no default values declared > will just be nil. Basically this would be the equivalent of this with > nicer syntax: > > old: > def foo(h) > h[:length] * h[:width] > end > > foo(:length => 10, :width => 20) > > new: > def foo(length, width) > length * width > end > foo 10, 20 > foo width:20, length:10 > Although I feel it's a bit too restrictive for Ruby, I could settle for that if implicit keyword arguments win the debate. But I still prefer explicit ones. On a side note, has the {a : 10, b : 20} alternative syntax for hashes that I've seen proposed a long time ago been adopted? -- Christophe Grandsire. http://rainbow.conlang.free.fr It takes a straight mind to create a twisted conlang.