[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Non-uniqueness of module names
- From: Hisham <h@...>
- Date: Thu, 18 Apr 2019 11:51:14 -0300
On Tue, 16 Apr 2019 at 18:43, Roberto Ierusalimschy
> > I would be more comfortable with _VERSION, with the Lua interpreter
> > itself, as "master module", already adhering to that convention :-)
The Lua interpreter does things that modules are not supposed to do,
such as loading a bunch of globals. It is an example of "main program"
behavior, not "module behavior".
But what about what the Lua reference manual says about using names of
"As a convention, programs should avoid creating names that start with
an underscore followed by one or more uppercase letters (such as
It even uses _VERSION as the example of what _not_ to do! :) I
understand that this can be interpreted as meaning "globals", and for
a while I thought that was the case. But then I've had to fix other
people's code in the wild that did not follow the recommendation above
and used _ENV as a regular *local* variable name in Lua 5.1, and
stopped working when Lua 5.2 came around. Now, when I read "names"
there I take it to mean any kind of name (locals, globals, module
names and members, etc). It does sound unlikely that a future version
of Lua would decide to make a particular module member name take a
reserved meaning, but if you asked me back in Lua 5.1 days I'd also
say it was unlikely that this would happen to a local variable name
I know I could have expanded the scope of my interpretation minimally
to have it mean "variables", but now I do the safe thing and avoid
underscore-uppercase names of all kinds. I understand that in this
particular case _VERSION is probably safe for the future (Roberto's +1
is a strong indication, of course, but language authors have changed
their minds before. :) ) In any case, following the manual's
recommendation has proven to be a safe bet in my own code.