From: Daniel Berger Date: 2005-10-22T00:44:58+09:00 Subject: Re: A comparison by example of keyword argument styles Yukihiro Matsumoto wrote: > Hi, > > In message "Re: A comparison by example of keyword argument styles" > on Fri, 21 Oct 2005 20:12:08 +0900, "Daniel Berger" writes: > > |Ruby has always favored implicitness over explicitness. The fact that > |I don't have to do anything explicitly in Sydney makes it the winner > |IMHO. > > Too much implicitness makes code cryptic. Too much explicitness makes > code verbose. It's a matter of balance. > > By the way, how do you delegate the whole arguments (including keyword > arguments) in your style? Using KeywordBehavior? > > Besides, what would happen for the following code? > > def foo(*args) > # how do you delegate arguments? > bar(*args) > end > > def bar(a,b,c) > p [a,b,c] > end > > foo(1,a:2,c:3) Not allowed because redefinition of the same parameter raises an error. Here you're trying to define 'a' twice, once as the first positional argument, once as a named parameter. For purposes of this argument, though, let's say you did this: foo(b:1, a:2, c:3) Then, if we inspect '*args' in foo, it looks like [{:b=>1, :a=>2, :c=>3}] For now, we're toying with the idea of an explicit behavior call to handle splat args in this case. So, the method definition would look like this: def foo(*args) bar(*KeywordBehavior.arguments) # Would pass 2, 1, 3 end Yes, it's uglier. How does it work in your implementation? I'm curious to know how you preserve argument order. > and > > class Foo > def foo(a,b,c) > p [a,b,c] > end > end > class Bar # what if argument names differ? > def foo(d,e,f) > super > end > end > Bar.new.foo(d:1,e:2,f:3) > > matz. > > We discussed this somewhat last night. There are a couple of possible routes to take. 1) Insist that parameter names must match, and raise an error. 2) Pass the arguments positionally. I think we're still undecided if I recall correctly. Let me ask you the same thing. What happens here with your implementation? class Foo def foo(a:, b:, c:) p [a,b,c] end end class Bar < Foo def foo(d:, e:, f:) super end end Bar.new.foo(f:3, e:2, d:1) Regards, Dan