Saturday, February 25, 2006

Names Aren't Forever

Dan Barlow refers to an article I wrote once on naming CLOS slot accessors, so I had better respond. Dan notes that choosing the name of a slot accessor or generic function is somewhat commiting because the name is used more globally than in other languages like e.g., Perl where a "slot name" is quite local. Xach responds that if you don't like a name, you can always change it later. I basically agree with this, but I want to point out that in large programs it may be difficult with text-based search-and-replace to make sure you're changing all -- and only -- what you need. Here our Java and Smalltalk friends are ahead with all the refactoring bells and whistles that come with integrated environments these days. Slime, the preferred environment for Lisp programming in GNU Emacs, doesn't even have a notion of all the files in a system. It does do a pretty good job of tracking the home package of symbols in a Lisp source file, based on the in-package forms in the file. It would be a cool hack to write a rename-symbol-in-system elisp function that visits all the files in an ASDF system, searches for a symbol and renames it if it's the symbol we care about i.e., in the right package. I call on my minions to make it so!

4 comments:

Zach Beane said...

This is a bit of a tangent, but in Perl, a very common style of objects (blessed hashrefs) has only strings naming slots. If you are subclassing such an object, you have to use care to give your subclass slots unique names, and this is sometimes done by prefixing the string hash key with the package name. It's like going backwards to elisp.

g said...

This is even more of a tangent, but your original article claims (at the bottom) to have been written by someone called "Tom Moore". Who he? :-)

Matthieu Lemerre said...

I thought about something like this a while ago, and I think that it should be further extended.

For instance, you should have a way to change the order of the params in every call, add a required argument to a call (and
add a default argument to every current call), change an argument from optional to keyword and so on... Basically, you should be able to change way to call a function while retaining compatibility with previous code.

Dave Roberts said...

Amen, brother. In this you are exactly right. I have been coveting the old rename-identifier command from Eclipse ever since I switched to Lisp. The remarkable thing is that I would think this might actually be easier to implement in Lisp environments since the syntax is easier to parse. Perhaps it's more difficult when one throws in the full cases of reader syntax table changes, etc.