unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Do we have to worry about the names of generic functions?
@ 2004-05-12 10:34 Andy Wingo
  2004-05-12 16:14 ` Paul Jarc
  2004-05-13 18:38 ` Rob Browning
  0 siblings, 2 replies; 10+ messages in thread
From: Andy Wingo @ 2004-05-12 10:34 UTC (permalink / raw)


Hi,

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
dispatch.

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
appreciated.
-- 
Andy Wingo <wingo@pobox.com>


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2004-05-15 19:53 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-05-12 10:34 Do we have to worry about the names of generic functions? Andy Wingo
2004-05-12 16:14 ` Paul Jarc
2004-05-12 20:34   ` Andreas Rottmann
2004-05-13 17:53     ` Rob Browning
2004-05-13 18:08       ` Andreas Rottmann
2004-05-13 19:49         ` Rob Browning
2004-05-14 19:40   ` Andy Wingo
2004-05-15 19:53     ` Paul Jarc
2004-05-13 18:38 ` Rob Browning
2004-05-14 19:53   ` Andy Wingo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).