lua-users home
lua-l archive

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

Has been discussed many times before (google will show many counter examples). By leaving it as globals, you can trap accesses (via metamethods) to undeclared variables which can help find those cases. Also as an example of just one problem with local by default:

function ternary(cond, iftrue, iffalse)
 if cond then
   res = iftrue
   res = iffalse
 return res

How often would you forget to write local res at the top of that function? If you don't, (with local by default) it'd just return nil. (Of course this is quite a contrived example, but it's not hard to see how often you'd still need to write "local" to ensure it has the scope of the correct block)

Besides, having to write local is still at least as easy as declaring c values at the top of their scope.

- Alex