Page MenuHomePhabricator

Consider implementing Module:No globals / Log globals in Scribunto itself
Closed, ResolvedPublic

Description

https://en.wikipedia.org/wiki/Module:No_globals
https://en.wikipedia.org/wiki/Module:Log_globals

This is a rather widely used module on enwp that prevents the usage of global variables. It seems like this would be useful to have integrated into Scribunto itself (working on the assumption that globals should be avoided).

Event Timeline

Anomie triaged this task as Lowest priority.Nov 13 2018, 2:24 PM
Anomie subscribed.

(working on the assumption that globals should be avoided)

That indeed is an assumption. I see no particular reason for Scribunto to enforce this.

If someone wanted to make it a pure-Lua library like bit32.lua that people could load on demand, meh. It would have to be relicensed or reimplemented though.

(working on the assumption that globals should be avoided)

That indeed is an assumption. I see no particular reason for Scribunto to enforce this.

I based it off of http://lua-users.org/wiki/ScopeTutorial, which says:

The general rule is to always use local variables, unless it's necessary for every part of your program to be able to access the variable (which is very rare).

Also partly my Python-bias where things are local by default, and that's the way I expect it.

If someone wanted to make it a pure-Lua library like bit32.lua that people could load on demand, meh. It would have to be relicensed or reimplemented though.

Ack, yeah, I was thinking it would roughly work the same in that people would need to manually require/enable it.

There's no obvious reason Scribunto should unconditionally enforce this when Lua as such doesn't, but that's an issue of defaults and somewhat orthogonal, IMO.

Looking at it with Perl eyes, things like "No globals" would be implemented in a module, but in a core module (as in, distributed with the interpreter) so it is always available as if it were a monolithic part of the language. It would act as a pragma, so it affects the interpreter's behaviour at compile-time. Since it acts like a module it can be turned on and off by the user (developer). In Perl land the nearest extant example would be something like "use strict;" that can be negated by "no strict;" (it has lexical scope). And its default can conceivably be affected by things like command-line switches passed to the interpreter (i.e. perl -w script.pl turns on use warnings;, and it can be disabled within a given lexical scope with no warnings; or its behaviour modified with no warnings 'experimental';).

In other words, I think some modules that behave roughly within the envelope of what could be called "pragma" (try to modify the language or interpreter behaviour) could beneficially exist as "core modules" distributed with Scribunto.

There's a similar case to be made for moving basic functionality into the standard library, but modules that operate that close to the language layer itself are somewhat of a special case.

Whether No globals and Log globals are good candidates for this I have less input on, but at least superficially they would seem to be reasonable to consider as examples if nothing else.

I discovered http://www.lua.org/extras/5.1/strict.lua today, which I think nicely covers most of the issues above, especially the licensing one. I'll work on integrating it as a "pure-Lua" library that Anomie suggested above. Invoking it as require( 'strict' ) fits nicely with Xover's comparison to Perl's use strict;.

As of today, on the English Wikipedia, "Module:No globals" is used on 32% of all pages, which I think justifies the move into Scribunto itself.

Change 834623 had a related patch set uploaded (by Legoktm; author: Legoktm):

[mediawiki/extensions/Scribunto@master] Add strict.lua to replace "Module:No globals"

https://gerrit.wikimedia.org/r/834623

Change 834623 merged by jenkins-bot:

[mediawiki/extensions/Scribunto@master] Add strict.lua to replace "Module:No globals"

https://gerrit.wikimedia.org/r/834623

Change 853514 had a related patch set uploaded (by Brian Wolff; author: Legoktm):

[mediawiki/extensions/Scribunto@REL1_39] Add strict.lua to replace "Module:No globals"

https://gerrit.wikimedia.org/r/853514

Change 853445 had a related patch set uploaded (by Brian Wolff; author: Legoktm):

[mediawiki/extensions/Scribunto@REL1_38] Add strict.lua to replace "Module:No globals"

https://gerrit.wikimedia.org/r/853445

Change 853526 had a related patch set uploaded (by Brian Wolff; author: Legoktm):

[mediawiki/extensions/Scribunto@REL1_37] Add strict.lua to replace "Module:No globals"

https://gerrit.wikimedia.org/r/853526

Change 853527 had a related patch set uploaded (by Brian Wolff; author: Legoktm):

[mediawiki/extensions/Scribunto@REL1_35] Add strict.lua to replace "Module:No globals"

https://gerrit.wikimedia.org/r/853527

Change 853514 merged by jenkins-bot:

[mediawiki/extensions/Scribunto@REL1_39] Add strict.lua to replace "Module:No globals"

https://gerrit.wikimedia.org/r/853514

Change 853445 merged by jenkins-bot:

[mediawiki/extensions/Scribunto@REL1_38] Add strict.lua to replace "Module:No globals"

https://gerrit.wikimedia.org/r/853445

Change 853526 merged by jenkins-bot:

[mediawiki/extensions/Scribunto@REL1_37] Add strict.lua to replace "Module:No globals"

https://gerrit.wikimedia.org/r/853526

Change 853527 merged by jenkins-bot:

[mediawiki/extensions/Scribunto@REL1_35] Add strict.lua to replace "Module:No globals"

https://gerrit.wikimedia.org/r/853527

I've seen a bunch of questions recently from third party users about module "strict" missing when they copy templates from wikipedia. Since copying wikipedia templates is such a common use case, and so many will use strict, I went ahead and backported this change.

There was no patch for the REL1_36 branch, is it an overlook?

There was no patch for the REL1_36 branch, is it an overlook?

1.36 is no longer supported.

Test wiki on Patch demo by Legoktm using patch(es) linked to this task was deleted:

https://patchdemo.wmflabs.org/wikis/e0d23a896e/w/

Mike_Peel subscribed.

After being abruptly told to make an edit on Commons to remove Module:No_Globals from WikidataIB (https://commons.wikimedia.org/w/index.php?title=User_talk:Mike_Peel&diff=prev&oldid=868602169), I finally traced the logic back to this ticket. I've added a link to this from the documentation [https://www.mediawiki.org/w/index.php?title=Extension:Scribunto/Lua_reference_manual&diff=prev&oldid=6470970] to help others find this ticket, and will make the edit, but there needs to be way better outreach to migrate all the uses described at https://www.wikidata.org/wiki/Q16748603 to this new solution.

Working link: https://www.mediawiki.org/w/index.php?title=Extension:Scribunto/Lua_reference_manual&diff=prev&oldid=6470970

Indeed the global deprecation of "Template:=" "Template:!" and "Module:No globals" should be stronger.

The discussion at Commons is indeed silly. How complicated can it be to remove a blatantly outdated comment line from a module?

Working link: https://www.mediawiki.org/w/index.php?title=Extension:Scribunto/Lua_reference_manual&diff=prev&oldid=6470970

Indeed the global deprecation of "Template:=" "Template:!" and "Module:No globals" should be stronger.

The discussion at Commons is indeed silly. How complicated can it be to remove a blatantly outdated comment line from a module?

There's nothing silly or blatant about this, and taking this approach just causes more problems. Please, focus on providing information that helps solve the issues, not causing drama.

Not sure what still needs to be done about this technically. The deprecation of the old module can be done by volunteers on wiki.

Not sure what still needs to be done about this technically. The deprecation of the old module can be done by volunteers on wiki.

My point was that those volunteers should be appropriately informed, with links to this ticket for background. But fair enough with marking this as resolved.

My point was that those volunteers should be appropriately informed, with links to this ticket for background. But fair enough with marking this as resolved.

Not that I don't agree that documentation should be better as a general stance, but notification about this change did go out in Tech News. In terms of notification (vs. documentation) I think that's reasonable.