Home> urticator.net Search About This Site > Domains Glue Stories > Computers Driving Games Humor Law Math Numbers Science Concepts for Persistent Objects > Language Design Principles Miscellaneous
|
Nameless CodeIt took a bit of thinking to find a good statement of this principle. My first thought was to say that code should be nameless, be able to exist and run with no names at all … but I soon realized that could just as well be a description of compiled code. My second thought was that code should also be able to be edited without names, but that wasn't right either. Names are too useful for referring to things to get rid of entirely.My third thought was in pictures. The names in existing languages are all tangled up with the code, so that the code can't exist without them, like this.
What I want is for the names to be separate from the code, for them to be part of the means by which the code is manipulated, like this.
With all the above in mind, I finally came up with the following statement.
Names should be external to code. Unfortunately, although I can state the principle, I can't really justify it. I have some weak arguments for it, but in the end the principle is just an idea that I find very attractive. The strongest of the weak arguments, I think, has to do with the idea that words are not reality. We use words, or names, to refer to things that are part of reality, but the things in themselves don't have names. Wouldn't it be interesting to have a language that modeled this aspect of reality? I imagine such a language would have almost magical properties. I got the rest of my weak arguments by trying to think of specific problems caused by names.
So much for justification. What I'd like to do next is look at some examples. I don't have any examples of the complete namelessness I'm looking for, of course, but I do have some examples of specific parts of code being nameless. (Are parts of code like parts of speech?) In Java, it's possible to create nameless classes. Here's an example from The Java Tutorial.
someObject.addMouseListener(new MouseAdapter() { I have to admit I find the syntax terribly confusing. The call new MouseAdapter() creates not a new MouseAdapter, but rather a new object belonging to a nameless subclass of MouseAdapter with its mouseClicked method overridden. It's well known that the lambda expressions that appear in functional languages such as Lisp and Scheme produce nameless functions. For example, the result of evaluating the following expression is a nameless function of one argument that returns the argument plus three.
(lambda (x) (+ x 3)) In statically scoped languages, it's possible to make the local variables nameless as well, like so.
(lambda 1 (+ (var 0 0) 3)) Here, the expression (var 0 0) looks up the first variable in the first enclosing frame. (Remember, index numbers start with zero.) We can even get rid of the expression and function names, by, say, creating objects (in memory) to represent each expression and function, then replacing all the names with pointers to the objects. And guess what? The result looks a lot like a compiler's intermediate representation of code … a representation that is very convenient for analysis and transformation. So, that's another good way to think of nameless code. If I could take the intermediate code produced by a compiler and refer to the different parts of it via the compiler's symbol tables, that would be almost exactly what I want.
Q: What's the point of replacing names with pointers to objects? Aren't pointers just another kind of name? Now that I've given some examples of parts of code being nameless, let me finish by mentioning a case in which code seems particularly nameful. Consider the following function (in C++).
template<class TYPE> As a template, or generic, function, it operates on objects of an unspecified type TYPE, and can be used to find the numerical maximum of integers, the alphabetical maximum of strings, or whatever. The part that's nameful is the less-than operator. Since the argument type isn't known in advance, there's no way to resolve the name “>” to any particular function.
|
See AlsoHierarchical Namespaces Words Are Not Reality @ January (2001) |