December 1st, 2010

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.