[Python-Dev] PEP 246, redux (original) (raw)
Phillip J. Eby pje at telecommunity.com
Tue Jan 11 19:03:18 CET 2005
- Previous message: [Python-Dev] PEP 246, redux
- Next message: [Python-Dev] PEP 246, redux
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
At 10:59 AM 1/11/05 +0100, Alex Martelli wrote:
all you have to do is ADD def conform(self, protocol): if issubclass(protocol, Abstract): raise LiskovViolation
that's all.
That will raise a TypeError if protocol is not a class or type, so this could probably serve as an example of how difficult it is to write a good Liskov-violating conform. :)
Actually, there's another problem with it; if you do this:
class Y(X): pass
class Z(Y): pass
then 'adapt(Z(),Y)' will now fail because of a Liskov violation. It should really check for 'protocol is Abstract' or 'protocol in (Abstract,..)' in order to avoid this issue.
Basically, rephrasing private inheritance with containment and delegation is a lot of messy work, and results in far more complicated structures. And instead of paying the tiny price of a conform call at adaptation time, you pay the price of delegating calls over and over at each x.tm1() call, so it's unlikely performance will improve.
Well, as I mentioned in my other post, such inheritance is a lot simpler with PEAK, so I've probably forgotten how hard it is if you're not using PEAK. :) PEAK also caches the delegated methods in the instance's dict, so there's virtually no performance penalty after the first access.
Again, not an argument that others should use PEAK, just an explanation as to why I missed this point; I've been using PEAK's delegation features for quite some time and so tend to think of delegation as something relatively trivial.
- Previous message: [Python-Dev] PEP 246, redux
- Next message: [Python-Dev] PEP 246, redux
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]