2 key aspects of a clean LaTeX package

I often get conflicts between distinct sty files, due to things as simple as variable names.

The latest one was between proof.sty (which permits to move proofs automatically to the appendix) and llncs.sty (which is required by many conference and journals to insure a homogeneous look and feel), which both define a variable named exercise and hence produce a conflict.

One solution would be to expect each sty file to prefix all its variables with the name of the library implemented, but this is not a clean solution. Is there any way in LaTeX to provide some encapsulation, or at least to define some local variables, as I think is the usage in modern programming languages?

– Jérémy Barbay, https://tex.stackexchange.com/questions/44373/does-latex-allow-for-namespaces-to-eliminate-the-risk-of-package-clashes

Provide a list of all publicly available macro names, in a form such as \ThisPackageDefinesMacros{ytableaushort, ydiagram, ytableausetup} and \ThisPackageDefinesEnvironments{ytableau}.

(...)

The user of the package can then reveal the macros they want, possibly all of them, using commands such as \UsingMacros[ytableau]{ytableaushort, ydiagram} or \UsingEnvironments[ytableau]{ytableau}. (As a convenience, the first argument should default to the last loaded package. As a further convenience, there should probably be something like \UsingAllMacros[ytableau] in case you don't care to pick and choose.)

https://tex.stackexchange.com/questions/44373/does-latex-allow-for-namespaces-to-eliminate-the-risk-of-package-clashes

There is the simplest name-packaging, what is called block structure:

\def\foo{\begingroup{%
  \def\bar{bar}\endgroup}

where the \bar is only available inside \foo's grouping, i.e., lexically scoped inside the group of calling \foo.
(with parameters, for example: \def\foo#1{{\def\bar##1{##1}\bar{#1}}})

I don't know why blocks aren't used more often with TeX; there might be a reason for that.

– Ryan Reich, https://tex.stackexchange.com/questions/44373/does-latex-allow-for-namespaces-to-eliminate-the-risk-of-package-clashes