From: James Britt Date: 2005-09-18T23:48:34+09:00 Subject: Re: proposed attr writer patch Daniel Berger wrote: > --- Mathieu Bouchard wrote: > > >>On Sun, 18 Sep 2005, James Britt wrote: >> >> >>>attr_accessor :foo?, :bar! >>>And would it not be better to just have people >> >>learn proper Ruby, rather than >> >>>add yet another exception to how Ruby behaves? > > > The current behavior is broken. Broken? Does that not depend on a certain point of view? Is it broken because Ruby does what it is told to do, rather than what the user may have meant it to do? I believe "attr_accessor " follows a simple definition. It creates def =( new_val ) @ = new_val end and def @ end But one has to use pick reasonable values for , and understand that a method named foo?= is probably not what is wanted. Basically, you get what you ask for, so ask wisely. > So, it should either > do something useful or raise an error. I vote the > former, though I would accept the latter. I'd prefer that latter, if the results are untenable Ruby, rather than masking the mistakes of a user by having the interpreter, um, interpret what the user *meant* to do. > > >>It can be said that Ruby has so many exceptions that >>just another >>one won't noticeably increase the number of them. >> >>It can also be said that Ruby has so many >>exceptions, far too >>many of them, that it's important to stop the >>invasion of more exceptions. > > > Again, I consider this a bug fix, not an exception, > since the current behavior creates syntactically > invalid methods. So, we can make it work as things > stand now, raise an error, or we can alter Ruby itself > to understand "?=" and "!=" as valid syntax (as you > mention in ruby-core:4406). > > So, unless either of you have got a better idea (and a > patch), I'm not sure what you're complaining about. > I'm generally against languages attempting to guess what I meant to do and then quietly doing something other than what I told it to do. If this construct can create invalid Ruby, won't there be an error when someone tries to call the invalid Ruby? I can see the value in raising an exception right off the bat, though I'm unclear what problem this is supposed to correct. If someone is writing attr_accessor :foo?, :bar! then the problem may not be that Ruby doesn't try to make sense of this, but rather that someone is writing code like that. James