From: Kent Dahl Date: 2002-08-10T19:46:18+09:00 Subject: Re: ambiguity between local variable assignment and writter method Tom Sawyer wrote: > 5. writer methods have an EXCEPTION in their behavior The real base of the exception is that Ruby allows some rather wierd symbols in the method names. Personally I'd be more likely to alias my writer methods to set_* methods, if I found myself using them alot from inside the class and annoyed at all the selfs. (But then again, C++ and Java will do the first to your brain and the latter don't apply to me that much :-) The exception is also tied to the ambiguity of optional parenthesis, allowed spaces between name and = when calling, and in general its a very exceptional thing to begin with, to help code outside the class be readable. One might use stricter call syntax on the inside of the class to get rid of the ambiguity without self, i.e. class X attr_accessor :x def test x=(5) # == self.x=5 x =(5) # == x = 5 x= (5) # == x = 5 end end But that seems like a bug waiting to bite also. > i agree. i don't want to add any new constructs. and i don't think we > need to in order to clear up this inconsistency. simply giving > precedence to writer methods would do it. Dave mentioned the performance issue, which I believe would be very significant. Upon parsing, every local variable assignment cannot be interpreted and optimized as a local variable assignment, but has to have a check to see if there was a method with that name at _runtime_, each and every time. Or you could do the decision only once at parsing time, and be dependant on the order of definition of methods. (I.e. put the writer methods below the method in question, and you're screwed.) So I don't think giving precedence to writer methods will suffice. -- (\[ Kent Dahl ]/)_ _~_ __[ http://www.stud.ntnu.no/~kentda/ ]___/~ ))\_student_/(( \__d L b__/ NTNU - graduate engineering - 5. year ) ( \__\_�|�_/__/ ) _)Industrial economics and technological management( \____/_�_\____/ (____engineering.discipline_=_Computer::Technology___)