lua-users home
lua-l archive

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


> > It's starting to become apparent to me that life would be easier
> > if new variables were local by default, instead of global.
>
> I have much trouble to program with php. Because in php new
> variables are local by default. Some powerfull programming
> techniques are impossible with that behavior. In php its impossible
> to do that:

Do you mean "local by default" or "can never be global", because it seems to
me, if local is just the default, then you can easily override that and make
variables you need to be global explicitely global yourself. In lua, global
is the default, but that doesn't mean that you can't make locals if you want
to.

Depending on your POV, you might think that defaulting to local is cleaner
because experience with other languages tends to make your brain think that
"int i" in a function isn't going anywhere else, and you have to go out of
your way to declare "i" in such a way that it's global.

Or you could think that defaulting to global is cleaner because it forces
you to explicitely make things that should be local local, which is probably
an aid to readability or something.

Personally, I can see the utility in it both ways, depending on how you want
to use the language. Which is why my opinion is that if anything does
change, it would be cool if you could work it either way, if it could be
done without a severe impact on speed and such.