On Mon, Feb 4, 2019 at 5:26 PM Eran Rosenthal eranroz89@gmail.com wrote:
What is the problem with the ".ext" part?
- It adds unnecessary complexity both in the extension (need to init
mw.ext if it doesn't exist)
It's one line in the boilerplate. That's not much complexity.
and more important - in its usage when the Lua extension is invoked (longer names)
It's 4 characters. Also not much to be concerned about. You're also free to do like
local foo = mw.ext.foo;
if you want shorter access within your code.
(there is very small risk of name collision - mw.ModuleA and mw.ModuleB are unlikely to clash as different extensions, and mw.ModuleA and mw.FUNC are unlikely to clash because function names < https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#Base...
are usually verbs and extensions https://www.mediawiki.org/wiki/Category:All_extensions are usually nouns)
Scribunto has its own built-in packages too, which are also usually nouns. What if, for example, Extension:Math https://www.mediawiki.org/wiki/Extension:Math added a Scribunto module at "mw.math" and then we also wanted to add a Scribunto-specific version of Lua's math library https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#Math_library? Or Extension:CSS https://www.mediawiki.org/wiki/Extension:CSS and a Scribunto counterpart to mw.html https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#HTML_library? Or if Extension:UserFunctions https://www.mediawiki.org/wiki/Extension:UserFunctions did its thing at "mw.user" and then we got around to resolving T85419 https://phabricator.wikimedia.org/T85419?
Having mw.ext also makes it easier to identify extensions' additions, avoiding confusion over whether "mw.foo" is part of Scribunto or comes from another extension. And it means you can look in mw.ext to see which extensions' additions are available rather than having to filter them out of mw.
BTW, we have "mw" in the first place to similarly bundle Scribunto's additions away from things that come with standard Lua. If someday standard Lua includes its own "ustring" or something else Scribunto adds a module for (and we upgrade from Lua 5.1), we won't need to worry about name collision there either.
- Practically the convention is to not use mw.ext - the convention (based
on most of the Lua code - e.g wikibase) is to not use mw.ext
Of extensions in Gerrit (as of a few days ago when I last checked), Wikibase and LinkedWiki seem to be the only two extensions not using mw.ext, while Cargo, DataTable2, DisplayTitle, DynamicPageListEngine, FlaggedRevs, JsonConfig, ParserFunctions, and TitleBlacklist all do.