--- In lua-l@y..., "J. Perkins" <jason@3...> wrote:
It's starting to become apparent to me that life would be easier
if new
variables were
local by default, instead of global. I'm about to go online and
look for
No, i absolutely disagree. At first it may appear to you that life
would be easier with default local variables, but in the end it's
not. It's all about scope and when you have local variables per
default you either loose some scope or have clumsy commands.
function a ()
local local_for_a_and_following=1
b()
end
function b()
return local_for_a_and_following+1
end
so this works now. if we rewrite this in local scope default we
would get something like this:
function a ()
local_for_a_and_following=1
b()
end
function b()
global local_for_a_and_following=1
return local_for_a_and_following+1
end
which either is very clumsy, because the global command would
indicate that local_for_a_and_following has real global scope or
simply doesn't work if you define the global statement to act as
expected and only give you the local_for_a_and_following from the
real global scope.
To introduce a Statement like subglobal wich works as expected is a
real overdose. This way round, declaring variables as local and
everthing else is global is the better one. PHP does it the other way
round, and therfore doesn't allow "subglobal" scope which is a real
pain in the ass. In Lua you can hide global variables if you do this
procedure, so your sure your function can't do real harm, in php
theres no way to do that...
best regards,
dominik
.