[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Say No to global-by-default
- From: Pierre-Yves Gérardy <pygy79@...>
- Date: Thu, 5 Jul 2018 13:47:25 +0200
On Thu, Jul 5, 2018 at 12:11 PM, Dirk Laurie <dirk.laurie@gmail.com> wrote:
> 2018-07-05 10:40 GMT+02:00 Viacheslav Usov <via.usov@gmail.com>:
>> On Thu, Jul 5, 2018 at 8:47 AM Marc Balmer <marc@msys.ch> wrote:
>>
>>> How was I unclear or neutral when I wrote "It's a bad idea?".
>>
>> That was not in response to "is this a problem worth solving",
>
> So the OP's diatribe against globals is to be split in three parts,
> each requiring that its predecessor is taken for granted.
>
> (a) the status quo is bad;
> (b) we need a way to specify whether a variable is global;
> (c) one such way is to put a dollar sign in front of the name.
I'd add a distinction between folks who think the way globals are
handled should stay the way it is and folks who are fine with it as is
but wouldn't mind if it changed.
I'd expect many Lua users to fall in that category.
Or folks who are split on the question. From a language standpoint, I
think it would be nice to have a distinct syntax for locals and
globals. From an ecosystem point of view, I'd be wary of such a
change.
A possible half-solution (that would trigger runtime errors) based on
the current language would be to do
local _, _ENV = _ENV, nil
You can replace `nil` with a table whose `__index` and `__newindex`
metamethods throw nicer errors (I have a `noglobals()` helper for that
with Lua 5.1 compat as well).
Then you can access `_.print`, etc, which is syntactically distinct
from locals. Compiler errors would still be better though.
—Pierre-Yves
- References:
- Say No to global-by-default, Egor Skriptunoff
- Re: Say No to global-by-default, Viacheslav Usov
- Re: Say No to global-by-default, Etiene Dalcol
- Re: Say No to global-by-default, Viacheslav Usov
- Re: Say No to global-by-default, Thijs Schreijer
- Re: Say No to global-by-default, Viacheslav Usov
- Re: Say No to global-by-default, Thijs Schreijer
- Re: Say No to global-by-default, Viacheslav Usov
- Re: Say No to global-by-default, Marc Balmer
- Re: Say No to global-by-default, Viacheslav Usov
- Re: Say No to global-by-default, Dirk Laurie