[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Uppercase-initial globals
- From: Lars Müller <appgurulars@...>
- Date: Wed, 22 Jun 2022 21:08:38 +0200
Implementing "actual syntax" is a nontrivial thing for Lua linters to
do: Lua is highly dynamically; apart from local & const annotations,
linters hardly know anything about your environment: The function
environment _ENV may be changed; the debug library may be abused to
access locals or modify the metatables of built-in types; metatables
might be set on various pseudo-"classes" or other objects; even the
global table may be tampered with. For a linter to properly work either
(1) Lua has to be restricted to a "reasonable" subset where e.g. it can
be safely assumed that everything in the global table is to be used as
indicated in the reference manual, where the linter needs to be made
aware of additions (e.g. through .luacheckrc), locals are heavily used,
_G is ideally not used at all (to make usage of globals predictable),
_ENV isn't used, the debug library is banished entirely from interacting
with program state (apart from pulling out debug info) or (2) the linter
solves the halting problem to know the metatables & lifetimes of all
your values as well as the scope of your global variables.
Linters are forced to pick option (1); it just varies from linter to
linter how restricted this subset is. Linters can't keep track of types
and thus can't keep track of metatables either. This linter appears to
thus force you to use string.sub because otherwise it couldn't tell
whether you aren't calling MyClass.sub rather than string.sub. This is
overly intrusive IMO.
I've found the best approach to be runtime strictness (f.E. type checks
or warnings when accessing nil globals that haven't been set before)
paired with nonintrusive, configurable linters like Luacheck that only
really warn you when there's a glaring issue in your code or they are
heavily misconfigured. It is to be expected however that a highly
dynamic language like Lua with all it's metaprogramming capabilities
can't have the same static analysis support as all the statically typed
On 22.06.22 16:08, Javier Guerra Giraldez wrote:
On Wed, 22 Jun 2022 at 08:50, Flyer31 Test <firstname.lastname@example.org> wrote:
On Wed, Jun 22, 2022 at 10:22 AM Egor Skriptunoff
A question about Lua coding style.
Is it a good or bad idea to distinguish global from local variables by its uppercase / lowercase initial letter?
... as I also use Visual Code for Coding (as your stackoverflow link),
I adapted to this.
so, a given editor invents some "convention" (that i've never heard of)....
Only thing which is a BIT nerving in Visual Code: It will signify the
":" operator as yellow curly error. (e. g. str:sub(1,4) will give
yellow warning, string.sub(str, 1, 4) will be fine).
... but don't implement actual syntax
does it make any sense?