lua-users home
lua-l archive

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


> No. In both versions failures are depending on
> the situation. In both versions the failure can
> be long hidden or found immediately.

However, local-by-default is easier to debug because of one simple thing: it
tends to mean that the bug in your code is close to the place at which it
shows up (in C, in the same function; with lexical scoping, in a textually
containing routine; with dynamic scoping, in a caller). With
global-by-default, you can get different uses of the same global interfering
in completely different parts of the program.

> In small programms global vars by default are welcome
> because you don't have to worry about variable scopes.
> Use them and its ok.

On the contrary, even in small programs different uses of global variables
can interfere. What I *do* find useful is dynamic scope, as in BBC BASIC, so
that you can define variables in one procedure, and have them accessible in
all callees.

> In big projects global variables are also welcome
> because you don't need to declare it global again and
> again in each function who need them. Instead you
> declare the locals because you use them only here
> and once.

But big programs are much easier to debug if you do declare globals where
they are used (I find this feature useful in OPL, a BASIC-like language on
EPOC (Psion) machines). It means you can tell at a glance which globals you
have to worry about at any given point, and it gives a rough-and-ready
measure of program ugliness (the more globals you import in a particular
routine, the worse, all other things being equal).

> It can't not the job of the language to prevent errors.

It should be, where possible.

> Sure,
> it should help you, but not in the way to make things
> complicated or to prevent features.

Certainly not to over-complicate, but a lack of structure can be bad too:
witness the current confusion over how to program objects and modules in
Lua. Similarly, type-checking is all about preventing badly-typed programs.

> You can simple
> delete files with one command. You would never say
> this is so dangerous let us make a complicate command
> to prevent this.

No, because that's a different sort of dangerous; the danger mentioned above
is the danger of complexity and introducing bugs, not the simple danger of
immediate, dire consquences. But you do have access control; you'd never say
"let's not have a read-only flag, because you can always check before
deleting a file".

-- 
http://sc3d.org/rrt/ | Academics age by degrees