emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Why :USE sucks in the Common Lisp package system


From: phoe
Subject: Why :USE sucks in the Common Lisp package system
Date: Sat, 9 May 2020 22:34:10 +0200

On 09.05.2020 20:48, Andrea Corallo wrote:
> I'm *not* sure we should and I'm not stating that now.  I suspect it
> would be worth, but we are really in early discussion and investigation.

Hey,

just noticed that one of my posts was mentioned here earlier; I thought
that I could provide a bit more context from the perspective of a Common
Lisp programmer, especially in the context of the namespacing discussion
for elisp.

In CL, we have packages that can :USE each other, and we have had them
ever since Common Lisp had become standardized. Recently (and I mean,
like, very recently - two, three years?), the support for a language
extension called package-local nicknames has emerged, mostly to resolve
the growing issue of global nicknames polluting global namespaces: BT
stood for Binary Types, but BT also stood for Bordeaux Threads, but BT
also stood for... And so on, and so on. This, however, has given the CL
community to work with one more issue in the CL ecosystem, which is :USE
abuse.

The major issue with :USE is its ubiquity - packages :USE literally
everything, a lot of other packages, even (and especially) code that
they have no control over. This means that they now depend on these
packages' exports not interfering with their code. Who can guarantee
that? No one, really, unless some manual or automated inspection of
packages is done.

This has led to de-facto ossification of some libraries upon which lots
of code depends, the most famous example being Alexandria, the most
popular CL library. If everyone uses Alexandria along with 20 or so
other packages, then if Alexandria introduces a new exported symbol,
then it may either generate package conflicts with other used packages
(this visibly breaks code) or its value/function/class/whatever cells
may be silently overwritten by a package that previously used to have
its own symbol with that name but now inherits it from Alexandria (which
*invisibly* breaks code).

I bet that a massive amount of Common Lisp code is written that way,
simply because PLNs did not even exist back when that code was written.
Previously, it was cumbersome to manually write (alexandria:assoc-value
...), so people resorted to :USE; nowadays, with PLNs, it is much easier
to write (a:assoc-value ...), and :USE is not required to write readable
code.

My point of view is that the package system with PLNs is good enough for
my use cases: I can :USE the COMMON-LISP package or perhaps one of its
replacements, such as COMMON-LISP+QT, and locally nickname all libraries
I use.

I hope that, at one point (meaning: when the CLISP implementation gets
package-local nicknames implemented), we will be able to go through all
of the code in Quicklisp and adjust it to reduce the :USE abuse, and
therefore free existing libraries from this unfortunate ossification.
It's a non-trivial amount of work to do, but I hope it'll be done.

While I'm no emacs programmer (this is my first post here!), I think
that a package system with PLNs could work for elisp as a tool for
symbol namespacing, as long as it is clear that elisp programmers know
not to repeat the mistake from the CL ecosystem and only use :USE for
packages that either do not change (in our case, it's the COMMON-LISP
package), or a package that changes but is the only used package (and
therefore has nothing to conflict with), or a combination of packages
that do not change and we have full control over so we can manually see
and resolve the symbol conflicts as they arise. And then, we locally
nickname everything, e.g. importing ALEXANDRIA as A, FLEXI-STREAMS as F,
BORDEAUX-THREADS as BT or just T, and write our code that way.

BR
Michał "phoe" Herda




reply via email to

[Prev in Thread] Current Thread [Next in Thread]