lua-users home
lua-l archive

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


How to implement the syntax "global var = 1"?
And force everybody to declare every variable before use it?
So that I don't worry about that correcting such silly mistakes occupy most of my time.

I don't like such syntax:
    global("var", 1)
It is so ugly compared with this:
    local var = 1;


2013/4/26 Steve Litt <slitt@troubleshooters.com>
On Thu, 25 Apr 2013 07:30:48 +0200
Thomas Jericke <tjericke@indel.ch> wrote:

> On 04/24/2013 11:09 PM, William Ahern wrote:
> > The most sensible and simplest rule is what Lua uses, IMO.
>
> I would prefer nothing by default.

I would too. If I really want something to be global, I'll

global myvar = 0

It's not like I'm going to have 40 globals anyway, so this won't be
much writing.

And of course, I'm a fast enough typist to do this for non-globals:

local myvar_local

I understand why defaulting to local would mess up a lot of good things
in Lua, but unless one is the type who seldom makes silly mistakes,
defaulting to global would result in lots of hard to troubleshoot
problems.

Thanks,

SteveT

Steve Litt                *  http://www.troubleshooters.com/
Troubleshooting Training  *  Human Performance