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:

Distribution
~~~~~~~~~~~~
function A defines many local variables
now function A call function B

function B is a distributor and don't know variables from
function A also it works as a distributor for many other
functions with other variables
now function B call function X, Y or Z relating on:
   example global language setting

function X, Y and Z need all variables from A


Recursion
~~~~~~~~~
function A defines many local variables
now function A call function B with the one recursive parameter

function B using all local variables from function A
now function B call function B (until job is done)



The benefits: We don't need to know the global name space and
can define our sublocal variables - availible in each subfunction.
The stack is only used for the one recursive variable. Each other
variable exits only once! If you give all variables as a parameter
you will need a *big* stack space.

In general: new variables were global by default
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
subfunction can use: all globals
                     own locals
                     the sublocal (local defined in caller-function)

In general: new variables were local by default
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
subfunction can use: all globals
                     own locals
                     *no* sublocals (local defined in caller-function)


I can't see new programming techniques if new variables were local by
default. But I like Lua so much because the scope of variables is
one of the best I have ever seen. Please let Lua as it is. Don't follow
bad C, Java... practice.

Regards


Markus