Re: Generics vs. Message passing: object namespaces
Pascal Costanza <[email protected]> Sat, 24 Feb 2007 15:43:21 +0100
| Newsgroups | gmane.comp.lang.lightweight |
|---|---|
| Message-ID | <[email protected]> |
On 24 Feb 2007, at 12:59, Tom Locke wrote: > Nice to see this topic has generated some interest :-) :) > Can I break this down into words of two syllables or less? > > The following (darn - blew it already) guide: > > http://www.aiai.ed.ac.uk/~jeff/clos-guide.html > > Contains: > ------ > A defclass that provided similar access functions, etc, would be: > > (defclass person () > ((name :accessor person-name > :initform 'bill > :initarg :name) > (age :accessor person-age > :initform 10 > :initarg :age))) > ------ > > Is this good CLOS or bad CLOS? Hard to tell. It's a toy example. In general, it's not a good idea to indicate the type name in accessors, but leave it to the package / module mechanism to disambiguate names. If you had a statically typed language with generic functions, it may also be an option to leave it the type system (but I am not aware of such a language). On the other hand, there is for example the CLOS MOP that uses this style of naming accessors (class-precedence-list, class-slots, generic-function-methods, etc.). > How about we rename those accessors to "name" and "age"? Good or bad? Probably good. > There is some interesting discussion of this point in the context > of Dylan here: > > http://www.opendylan.org/books/dpg/db_125.html > > Quote: "Therefore, for getters that you intend to export, it makes > sense prevent clashes by considering the name of the slot > carefully. One technique is to prefix the name of the property with > the name of the class" I can't comment on this because I don't know Dylan that well. > And a couple of general points... > > In practice, programmers using object-dispatch languages have no > difficulty understanding where a call is going when the see > something like "file.name". Yes the namespace is implicit rather > than explicit, but people are good at context! Honestly, this is a > BIG reason why people like object-dispatch. It is. Honestly. I don't buy into this. For me, the big win of OOP always was ad-hoc polymorphism, i.e., the ability to invoke different variations of the conceptually same operation without the need to write extensive if- statements everywhere. It never was about the ability to clutter the same names with completely unrelated functionality. > Can we try to avoid this degenerating into "my language is better > than your language"? The question at hand relates to a very > specific comparison of the two styles. The answer I'm hoping for is > either "no, this is not a valid advantage of object-dispatch > because ...", or "yes, that's one advantage object-dispatch has". > If the answer turns out to be the latter, feel free to append "but > overall I still prefer generic-functions because ...", if that > makes you happier :-) No, "it" is not a valid advantage of message sending. ;) Even some Smalltalk implementations have introduced constructs for explicit namespace control. I guess they had reasons for doing so. Pascal -- Pascal Costanza, mailto:[email protected], http://p-cos.net Vrije Universiteit Brussel, Programming Technology Lab Pleinlaan 2, B-1050 Brussel, Belgium