<br><div><span class="gmail_quote">On 3/8/07, <b class="gmail_sendername">Bill Janssen</b> &lt;<a href="mailto:janssen@parc.com">janssen@parc.com</a>&gt; wrote:</span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
There&#39;s an incomplete wiki page about a possible factoring of types at<br><a href="http://wiki.python.org/moin/AbstractBaseClasses">http://wiki.python.org/moin/AbstractBaseClasses</a>.</blockquote><div><br>The one thing that I have been unable to figure out (from that page, the python-dev/python-3000 messages on the subject and talking with Guido) is why ABCs are better than explicit interfaces like Twisted and Zope use. I think mixing in abstract baseclasses in the normal inheritance tree is a mistake, and if you have a separate tree, you really just have interfaces. I can think of a half dozen nagging warts that will pop up with using ABCs instead of interfaces, most of which I already griped to Guido about (but failed to convince him.)
<br><br>&nbsp;- You can&#39;t take a third-party object, not participating in the ABC/interface craze, and say &#39;it inherits from this ABC&#39; (which you can do for interfaces.)<br>&nbsp;- If the abstract classes hold actual attributes (as is the suggestion, as far as I can tell) rather than be completely empty, they can end up in the middle of the inheritance tree and mess up MRO.
<br>&nbsp;- If the abstract classes are really completely empty, you need another mechanism for figuring out what a particular abstract class entails.<br>&nbsp;- You can&#39;t define *any* &#39;magic&#39; on the abstract classes, things that are supposed to work on ABCs only, because any inherited class will of course automatically inherit the magic. If you use a magic metaclass for ABCs that works around that, people &#39;implementing&#39; classes with their own metaclass will have to remember to subclass their metaclass from the ABC-magic-metaclass.
<br>&nbsp;- Because of the no-magic thing, you can&#39;t have the ABC do useful things, like asking it to verify if an implementation class has the right attributes or whether it can find an adapter for one ABC to another.<br>
&nbsp;- You can&#39;t un-inherit an ABC, ever. You can&#39;t inherit from a particular class to get some free implementation, but provide a slightly different (conflicting) interface. (Alright, probably not realistically a problem, but still.)
<br></div>&nbsp;- Mixing interface-definition and implementation like that makes it hard for new programmers to pick up the difference. It will be harder to explain the difference between &#39;dict&#39; and &#39;Mapping&#39; when they are both in the list of bases. How can you tell one from the other?
<br><br>As far as I can see, there is tremendously little difference between ABCs and interfaces, at least the way Guido explained his ideas for ABCs to me. The entirely Wiki page can be turned into a list of interfaces with a few textual edits. The only difference is that ABCs nestle in the normal MRO, which, in my eyes, is not a benefit at all. So... what&#39;s the actual benefit of ABCs over interfaces?
<br></div><br>-- <br>Thomas Wouters &lt;<a href="mailto:thomas@python.org">thomas@python.org</a>&gt;<br><br>Hi! I&#39;m a .signature virus! copy me into your .signature file to help me spread!