Re: Generics vs. Message passing: object namespaces
Pascal Costanza <[email protected]> Sun, 25 Feb 2007 14:54:59 +0100
| Newsgroups | gmane.comp.lang.lightweight |
|---|---|
| Message-ID | <[email protected]> |
On 25 Feb 2007, at 14:35, Tom Locke wrote: >>> And not knowing the type isn't just an unwanted side-effect, it's >>> actually the goal. Dynamic OO is about escaping from fragile and >>> inflexible type dependencies by using type independent messages >>> instead of type dependent functions. >> >> You still haven't told us how you disambiguate the draw message >> when your object inherits both from a weapon and a picture. >> Especially when both draw messages have the same signature. > > If there is type information associated with the *reference*, not > the object, e.g. as in a statically typed language, this can be > used to disambiguate. C# does this. In my first response to your question (February 22, 11:33), I already said that type systems are used to manage namespaces. That's exactly what I meant. And C# goes beyond Java here because it provides ways to disambiguate cases where Java just blocks. IIUC, C# is similar to C++ in this regard. So in those border cases, you can say Gun::draw and Picture::draw, for example. (I don't know the C# syntax off the top of my head, so I am probably wrong wrt syntactic details.) > Dynamically typed languages do indeed run into a problem. As you > pointed out you will have to use something along the lines of an > adapter object, and yes, run into object identity worries. Right. > It is conceivable that you could run into a big problem if you face > just the right interaction between multiple inheritance, > polymorphism and object identity. In practice this seems to be > extremely rare. Is this a big enough deal to dismiss object- > dispatch in dynamically typed languages? I'd say no, but that's > more of a judgement call than an absolute. > > What I wish I was more clear on, was how often, in GF based OO, one > ends up using names that object-dispatch people would consider > overly verbose, whether it be draw-gun at the definition site, or > gun:draw at the call site. > > Answer: all over the place => big win to object-dispatch > > Answer: very rarely => big win to GFs > > (note to black-and-white types: I did not say "overall win to ...") > > The reality is probably in between, and maybe only a lot of > experience with both styles would shed light (combined with a > detached state-of-mind!). Yes, I guess it's in between. In my experience, the important change in naming conventions comes from switching between an object-dispatch language vs. a Lisp/Scheme- style language, not from switching between object-dispatch and generic functions. I don't notice strong differences between names for plain functions and generic ones, at least not in Common Lisp. Pascal -- Pascal Costanza, mailto:[email protected], http://p-cos.net Vrije Universiteit Brussel, Programming Technology Lab Pleinlaan 2, B-1050 Brussel, Belgium