[racket] Should we _always_ use `only-in` or `prefix-in` when `require`-ing packages?

From: Konrad Hinsen (konrad.hinsen at fastmail.net)
Date: Mon Nov 18 11:42:17 EST 2013

Greg Hendershott writes:

 > Pre-caveats:
 > - Maybe this has been discussed before?
 > - This is true (IIUC) of the old Planet as well as the new package system.
 > - Maybe it's true of every package system.

It's certainly a problem with many package systems.

I have run into the exact situation you described in Clojure, when
clojure.core (the fundamental namespace of the language) was enhanced
with new names, two of which I had used in my own modules. I proposed
a solution in my clj-nstools library
(https://code.google.com/p/clj-nstools/source/browse/src/nstools/clojure_1_0.clj),
but I don't think anyone except me ever used this.

In the Python world, the general recommendation is not to use "from
XXX import *" (which is the equivalent of a require in Racket) except
for interactive use, or perhaps in small use-once scripts. But not
everyone follows this advice.

In practice, whether not this issue is a problem depends on how stable
one's dependencies are. I don't expect much trouble with (require
racket/string), but some new and rapidly evolving library might need
more precautions.

One potentially useful support tool would be a code analyzer that
replaces a plain require by a require with only-in followed by the
list of names from that package that are actually used. Developpers
could apply the transformation before publishing a package, for
example.

Konrad.

Posted on the users mailing list.