lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Bret Victor wrote:
> The creator of Ruby thought as you did.  He later realized that
> implicit declaration of locals was the "single biggest design flaw"
> in the language.

FWIW, that's not what Matz (creator of Ruby) was talking about. 

What Matz actually said[1] was:

   [...] I needed block local variables, so I made
   the current local variable scoping rule, which is
   "when a new local variable appears first in a block,
   it is valid only in the block".

   And *I was wrong*.  This rule is the single biggest
   design flaw in Ruby.  You have to care about local
   variable name conflict, and you will have totally
   different result (without error) if they conflict."

He was talking about cases like this (Ruby) code:

def foo()
  bar = 12          # a function-local variable
  [1,2,3].each{ |i| # An anon function with local variable 'i'
    bar = I         # bar is re-used from the function
  }
  print( bar )      #=> 3
end
 
def foo()
  [1,2,3].each{ |i|
    bar = i         # 'bar' is a variable local to this 'block'
  }
  print( bar )      #=> ERROR: undefined local variable or method `bar'
end


[1] http://wiki.rubygarden.org/Ruby/page/show/LocalVariablesAndBlocks