From: Charles Oliver Nutter Date: 2007-01-09T17:42:25+09:00 Subject: Re: [ ruby-Bugs-7680 ] a block argument within a block which argument has the same name leaks Evan Phoenix wrote: > Of course methods need local variables, but blocks would have local > variables still, just all in the scope of their defining method. Why do > closures need to have their own, unique variables outside of the scope > that they enclose? Smalltalk gets along quite well with all blocks > sharing the same local variable scope. The current scope rules are a > problem for a lot of new ruby programmers. Lots of them see the current > behavior as a bug that they have to work around. Evan and I discussed this at length on IRC and I came up with one area that could be damaged by a "flat local scope": DSLs In a large script using a complicated DSL, you would have to make sure all variables were named independently. Even worse, future revisions to that script would have to continue to maintain unique variable names across the entire script. Evan and I do not see eye-to-eye on this, but we agree on many other points: - no way to explicitly scope variables is confusing - bugs arise from missing explicit scoping And we disagree: - I believe lexical scoping is useful and necessary even with problems - I believe no lexical scoping would be far worse than not explicitly scoping variables But we both speak from the point of view of Ruby implementers, so we do not know how correct or incorrect we may be. -- Charles Oliver Nutter, JRuby Core Developer Blogging on Ruby and Java @ headius.blogspot.com Help spec out Ruby today! @ www.headius.com/rubyspec headius@headius.com -- charles.nutter@sun.com