From: David Chelimsky Date: 2007-01-20T20:58:07+09:00 Subject: Re: auto assign arguments? On 1/20/07, Robert Dober wrote: > On 1/19/07, Yukihiro Matsumoto wrote: > > > > Hi, > > > > In message "Re: auto assign arguments?" > > on Sat, 20 Jan 2007 01:58:06 +0900, "David Chelimsky" < > > dchelimsky@gmail.com> writes: > > > > > > > > Besides that, I think formal arguments of a method (including their > > names) can be seen as part of class API. Allowing instance variables > > as formal arguments seems like disclosing the internal issues. > > > Yes exactly but by explicit declaration, so > > def set_length(@length) > > just would be a willful disclosure a little bit like > attr_writer :length > Thinking about this some more - I wasn't proposing this become part of the API. Nor would I want to see this anywhere besides the initializer. The proposal is that for initializers (only) you could define (not reference pre-existing) instance variables: def initialize(@length) end If this were allowed, there would be no need to expose the @ in RDoc. RDoc could be tweaked to hide that, so you'd still just see: new(length) Note that RDoc is already hiding initialize (as an instance method) and showing you new (as a class method), so this would just be an addition to that transformation. So the proposed sugar would only be exposed to the intialize method and anybody (human or machine) reading the class definition. David > But your reasoning is sound of course I feel it more important is the > unification of > method and block parameter behaviour which you have achieved in 1.9. > > It would be interesting why you allowed instance variables in blocks, maybe > because blocks are > not exposing an API? > I am confusing myself ;) > > Finally, I admit that the code like this > > > > def initialize(@length) > > end > > > > is longer than > > > > def initialize(length) > > @length = length > > end > > > > but I feel the intention of the latter code is far clearer than the > > former. > > > I agree the first is a little bit against POLS, I do not know any other > language where you can > define instance variables as formal parameters. > I am sure someone will fill this gap quickly though ;) > > matz. > > > > > Cheers > Robert > > -- > "The best way to predict the future is to invent it." > - Alan Kay > >