On Wed, Feb 05, 2003 at 04:42:55AM +0900, Yukihiro Matsumoto wrote: > |Myself, and several others on this list, feel that this warning should be > |optional. It's not really necessary at all, unless you're concerned about > |making your scripts run on earlier versions of Ruby. > > But I still hate shadowing, strong enough to raise warning. I think we'd all be reasonably happy with this warning as long as we compromise on it being turned on with -w. You might hate shadowing, but many of us happily re-use our little local variables like 'i' and 'j', which works just fine as long as the values don't persist more than a few lines. I think the point is, will this warning help you avoid shooting yourself in the foot? Under the current implementation of Ruby, because of 'action at a distance', it would be useful to have a warning the other way round: i=0 ... ... many lines ... [1,2,3].each { |i| # WARNING! i is bound to the global scope! ... } But that's because you expected a local variable, and it might trip you up if you get a method-wide one instead. The converse is very unlikely to be a problem: i.e. you ask for and get a block-local variable, and it just happens to be shadowing something you used once and forgot about 10 screenfuls ago. In fact it's so unlikely to be a problem that I would say don't warn at all, if it weren't for the backwards compatibility issue. To be honest, ruby's -w doesn't seem to catch very much anyway, although I keep it on just as a habit from perl. This sort of warning may increase its usefulness. But when running production scripts, under a web server for example, the less garbage you can spew onto stderr the better. > |(2) I asked for a warning (optional, with -w) if a local variable is > |assigned but not used. Examples would be: > > Nobu once made a patch for this. I didn't merge it because it's > little bit ugly in the current implementation. But I like the idea. > I will definitely add this check in the future release. Thank you, that will be another boost to the usefulness of -w ... Regards, Brian.