Restrict global namespace pollution #94
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently we are creating lots of global variables. E. g. in
dev
we currently define the following globals:Category 1: (official interface)
Category 2: (inofficial interface)
Category 3: (
fontloader
internal orluaotfload
-fontloader
interface)Category 4: (
fontloader
, should probably belocal
)Category 5: (
luaotfload
, should belocal
)Special (ignore for now, will be handled in the
bidi-dev
branch)I sorted them into categories based on who causes them and how easy it is to get rid of them. Category 1,
luaotfload
, is ok: It is our "official" interface to the outside world. Category 2 are globals created by the fontloader which are used by third party packages and became a less official part of out interface. We should keep them to avoid breaking things.So let's move on to the more interesting categories. Category 3 are globals created by the fontloader which are basically useless to the outside world. They occupy very nice names which could be used for other stuff without providing much value. (Most of them only provide dummy functions to avoid errors when the fontloader tries to call ConTeXt handlers) I would like to get rid of these.
Category 4 and Category 5 are "accidental globals": They are variables for which I do not think that there is any reason why they should be global in the first place, they are created by typos or missing
local
s.readarray
is created by the fontloader, so is should either becomelocal
in ConTeXt or it can be handled together wit Category 3.This PR consists of two steps, implemented in two commits:
luaotfload.fontloader
.Before this gets merged, we should do some additional tests especially for the second step: Is there any external code which relies on these globals? (I couldn't find such code, but searching for terms like
experiments
orstatistics
in CTAN leads to lots of false positives, so I might have missed something. Also not everything is in the CTAN...)If we find such code: Is it an important use-case? Then we could move the affeted globals to category 2 and keep them. Otherwise can the external code be changed to use
luaotfload.fontloader
?The other question is if we even want such a change. It would make valuable names available and ensure better isolation of the fontloader, thereby reducing the risk that third-party code which accidentally uses the same names affects the fontloader, but on the other hand it risks breaking compatibility if some users relied on eccentric interfaces of the fontloader.