[Python-3000] Builtin iterator type
Nick Coghlan
ncoghlan at gmail.com
Tue Nov 21 16:25:19 CET 2006
Aaron Bingham wrote:
> Bill Janssen wrote:
>
>>> Java interfaces are very useful, however. Java programming seems to be
>>> less and less about inheritance and more and more about implementing
>>> interfaces; at least it does amongst Java programmers with taste :-)
>>>
>> It seems to me that that's where Python has a real advantage. With
>> real support for multiple inheritance, Python "interfaces" could be
>> real classes (either like real Java classes or Java abstract classes),
>> perhaps providing default implementations. You get the goodness of
>> mix-ins, along with interface communication.
>>
> I agree. In Java, interfaces are necessary because multiple inheritance
> is not supported. I see no good reason to add an additional language
> mechanism for interfaces when multiple inheritance would do the job, AFAICT.
Just because multiple inheritance is *possible* in Python, don't make the
mistake of thinking that it is straight forward. Aside from mixin classes that
themselves inherit directly from object, multiple inheritance can get very
messy outside of tightly controlled type hierarchies (cooperative calls in
particular can become a nightmare). This flies in the face of Python's use as
a glue language to tie multiple components together (particularly given the
problem that some of the elements being integrated may come from environments
that *don't* support multiple inheritance, like the JVM).
The idea of a formal interface mechanism is to have something which conveys
the desired information *without* all of the additional issues that come with
using multiple inheritance.
It's similar to the rationale behind adding class decorators, even though
everything that a class decorator can do could be done with a metaclass
instead: getting a metaclass right is *hard*, but getting a class decorator
right is relatively easy and permits many of the things that programmers would
currently have to use a metaclass for.
Similarly, it's obviously possible to do interfaces in current Python (Zope,
PEAK and Twisted all use them, after all), but the question is whether or not
it can be made *easier* (both to write, and, more importantly, to read).
Regards,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
---------------------------------------------------------------
http://www.boredomandlaziness.org
More information about the Python-3000
mailing list