[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Do we have to worry about the names of generic functions?

From: Andy Wingo
Subject: Do we have to worry about the names of generic functions?
Date: Wed, 12 May 2004 11:34:08 +0100


I have a question for people, the answer to which will hopefully lay to
rest a lot of namespace-related debate. That question is, do we have to
worry about the names of our generic functions?

I've been trying to think of reasons for worry, and arguments against
the reasons, if I can find them. They're discussed below. Feel free to
add any that I missed, or correct anything that's unfair.

* Generics clobber the namespace.

I was inclined to believe this, but now I'm not so sure.

Consider a generic, `output'. I assert that x.output() in Python does
not clobber the namespace. x.output is syntactic sugar for referencing
the output field of x, and () means to invoke the returned object. If
output is a bound method, that means it will be invoked as output(x) --
exactly the same as (output x) in guile. The only difference regards
field lookup, which can be viewed as a limited version of multi-method

Although the name `output' is available to the world, the fact that it
is specialized restricts its validity to a certain subset of objects.
This subset is similar to python's "set of objects that have a field
named `output'".

To put it another way: what's the difference between (output x) and the
more smalltalk-like (x 'output)? The argument above leads to the
conclusion that there is no difference, and therefore that generics do
not clobber namespaces.

Is there a hole in that argument?

* Dispatching a generic with many methods might be inefficient.

If this is a problem, it should be solved in GOOPS.

* Using generics might be less readable.

This is indeed a problem. It can be solved by making generic names more
descriptive, or more commonly to make variable names more descriptive.
After all, x.output() doesn't tell you much, either.

* It's not obvious, when you read code, that you're calling a generic.

Hm. Well the short names of most of them is a clue ;) But seriously, I
don't know what to do here. JScheme has java-dot notation, where calling
java methods is done like (.uglyMethodName x), which is ugly but more
obvious. Some naming convention would be good here, I think...

* Conclusion

So, I haven't yet decided about naming generics. The debate comes up in
the context of g-wrap, a FFI-generating library. It exports some generic
functions as part of its API, and it's odd to see a library export
symbols like `visible?' and `add-item!'. All input on this issue is
Andy Wingo <address@hidden>

reply via email to

[Prev in Thread] Current Thread [Next in Thread]