Daniel Weinreb on packages

Daniel Weinreb has posted a number of really interesting things to the "pro" mailing list lately. I particularly like this digression on packages:

(Digression: A slightly different approach is to define a package not intended to be "use"'ed. I did this with the API for the logging facility in QRes. For example: log:add-rule. If you did a "use", it might be confusing to remember that add-rule is from logging, and indeed you might "use" another package that has an "add-rule" function. This is a name conflict. The whole idea of packages is to avoid name conflicts! So I think "use" is opposed to the whole idea of packages and should be used sparingly.

What people usually do in Common Lisp, in my experience, is to name their functions so that the ones in one module (or, more generally, related ones) all have names starting with a common prefix. Well, that's what packages were invented: so that you don't have to do that! In QRes, even though there is a "qconfig" package for the configuration stuff, the functions are still all named "config-", and everybody uses "use". I think this is not as good as using packages as they were designed. Rather than, e.g., config-descriptor-property, use config:descriptor-property. Anyway.)

My experience has been a bit more positive. I think that people use the "bad" style (redundant symbol prefixes for functions, slots, etc) as first instinct when coming to Lisp from other languages, and after a while they use the "good" style.

It would be nice if this transition time could be shortened, not just for naming style but for everything. Practical Common Lisp helps a lot, but it would be nice if there was more promotion of exemplary, modern CL code for people to study.

You can read more of Daniel's recent posts on the "pro" archive.



Re: Packages aren't really lispy

This sounds like Paul Graham brain damage to me.


Re: Packages aren't really lispy

The brain damage being the tendency to be more interested in the idealized language than in the dialect you're using? I don't think that's because of Paul Graham; Lispers have always done that, and it's probably a good thing, when it leads people to fix problems rather than tolerate them. But maybe the unpopularity of the package system is a red herring here, because the ugly parts are not the parts that attract usage advice.

The basic package advice (in-package; not adding prefixes to everything; not using up the short nicknames if you're making a library for distribution) applies to most module systems, so it may be overlooked for not being Lisp-specific. Some popular practical advice (defpackage in a separate file; very unique package names; nicknames instead of use) can be ugly and inconvenient and has no immediate benefit, so it's hard to convince people it's the right way. User-defined nicknames are as good a solution to name collisions as any language has, though, so maybe the standard advice should suggest rename-package or Didier's nickname-package.

Of course, the ideal would be something like (ql:quickload "foobarbaz" :nickname :fbb), if Quicklisp were omniscient enough to know which package to rename. :)

- arcanesentiment

Re: Packages aren't really lispy

The brain damage is not knowing much about Common Lisp as people normally write it, and thinking Platonic Lisp advice is useful or interesting.

April 2015

Powered by LiveJournal.com