Re: Generics vs. Message passing: object namespaces
Pascal Costanza <[email protected]> Fri, 23 Feb 2007 11:07:27 +0100
| Newsgroups | gmane.comp.lang.lightweight |
|---|---|
| Message-ID | <[email protected]> |
On 23 Feb 2007, at 10:15, Tom Locke wrote: >> If you need to have both 'draw' generics you then rename them on >> import when defining the module so they are distinct. > > Which is precisely the problem - I can't have picture.draw, > gun.draw and curtains.draw in the same source file, even though, as > a human reader, that would cause me no difficulties whatsoever. > Rather, it makes the code much easier to read. ...but for example with the Common Lisp package system, you can have (paintings:draw picture), (weapons:draw gun) and (decoration:draw curtain). When you're in a package that :uses, say, weapons (for example, it's clear that it doesn't use any of the other mentioned packages), you can just say (draw gun). > Pascal: >>>> With a good module / package / type system, you can say (append >>>> buffer x) when it's unambiguous what you mean, and >>>> (buffer:append buffer x) when it's not. >>>> >>> >>> Does "good" mean better than anything we currently have in a >>> production-grade language? >>> >>> CLOS and Dylan do in fact suffer from type-name-in-the-method- >>> name syndrome do they not? >>> >> >> The simplest answer I can think of is this: Generic functions are >> just functions, so any approach that solves namespace management >> issues well for function names is automatically also good enough >> for generic function names. > > The simplest answer, it seems, is not always the clearest! So far > no one has disputed that real-world Dylan and CLOS do actually have > this problem. Why is your "good enough" solution absent? The problem is not harder than elsewhere. If you see large libraries for message-sending-based approaches, there is also a tendency to get more "verbose", so it doesn't seem to have anything to do with generic functions vs. message sending. I don't mention a specific solution because I consider this an orthogonal issue. I could use this opportunity to praise the Common Lisp package system, which in my opinion solves all naming problems with a single mechanism in an excellent way. However, since I know only two or three people who agree with me that that's the case ;), this would just branch off to an otherwise unrelated subthread about proper namespace management approaches. I'd like to avoid that here. So I'll stick to my original statement: Whatever mechanism solves naming issues well for you, will also solve naming issues for generic functions. (Just to name two other examples: Dylan has a module system that is different from Common Lisp's package system, but was designed alongside Dylan's object system based on generic functions, so they probably have a good solution here. There exist a number of module systems for Scheme, and I would be surprised if they didn't mesh well with generic functions either.) Pascal -- Pascal Costanza, mailto:[email protected], http://p-cos.net Vrije Universiteit Brussel, Programming Technology Lab Pleinlaan 2, B-1050 Brussel, Belgium