From: Johan Holmberg Date: 2003-12-29T04:01:53+09:00 Subject: Re: Inconsistent value of uninitialized variable Gavin Sinclair writes: > [...] > This, to me, is inconsistent and undesirable behaviour. I would > prefer this: > > x = x # NameError: undefined local variable or method `x' ... > > I haven't given it much thought, but the existing behaviour cost me 15 > minutes debugging, and I: > * don't see a benefit of the existing behaviour; > * do see a benefit (consistency) of changing the behaviour. > I had a similar problem a while ago that also took time to debug. I had code looking something like this: x_misspelled = 33 ... x = 100 if x == -1 Because of the rule Matz referred to in his reply to your mail (that "local variables are defined when they first appear in the left side of assignment"), this code doesn't give an error. If I had written x_misspelled = 33 ... if x == -1 x = 100 end I would have got a NameError saying "undefined local variable or method...". I think these two code fragments does the same thing "logically", and that it would have been nice if the if-modifier-form also had caught my error. /Johan Holmberg