Python vs C for a mail server

Paul Boddie paul at boddie.org.uk
Wed Feb 1 12:45:41 EST 2006


Magnus Lycka wrote:
> In C++ it's the opposite. By demanding a particular type, we restrain
> ourself to using a set of values which is much smaller than the logic
> calls for, or we can throw away all type checks by e.g. casting to void
> pointers.

The main reason for evading the type system in such a severe fashion in
C++ is to break out of class hierarchies (noting that downcasting is
achievable in a slightly safer fashion). Ideally, one would design
class hierarchies in such a way that such break-outs are avoided, but
this can involve a lot of argument/discussion about design/architecture
that is mostly unnecessary with Python.

> I don't have enough experience with languages that provide interfaces,
> such as Java, to understand how useful they are, but it's my impression
> that they are too cumbersome to use fully.

My experience is the opposite: if one follows the recommended practices
with Java, the flavour of object-orientation employed is more
interface-oriented than anything else. Ages ago, there was a trend
towards describing class relationships using conformance rather than
inheritance; that there's still an incentive to rely more on
inheritance in Python-based systems has a lot to do with Python's
arguably better support for inheritance than Java, that doing away with
multiple inheritance in Java forced people to look at other ways to
model their information, and that conformance is typically dynamic and
implicit in Python anyway.

> As far as I understand, most Java APIs use types more than interfaces
> for parameters and return values. (I browsed the Java API docs at java.sun.com,
> and as far as I see, it seems the APIs always require parameters of distinct
> classes or types, and return values of particular types or classes.)

I can't comment on "most Java APIs", but if you look at established
packages like java.io and java.util, both are heavy on interface usage.

> I know that there have been attempts to provide interfaces in Python,
> and it seems Zope Interfaces are getting a decent following, but
> I don't think anyting like that will ever take the place that type
> declarations of all function and class declarations have in e.g.
> C++. It's too difficult to make interfaces so convenient and
> flexible that they could be used generally in Python without taking
> away a lot of power.

Generally, interfaces provide a fairly convenient means of expressing
the capabilities of objects whilst providing information that can be
useful, in conjunction with a suitably designed runtime environment, in
the generation of fairly well-optimised code. In a sense, what you say
about "taking away a lot of power" is highly appropriate: by imposing
an interface system on Python, it's quite likely that one could gain
performance and a certain measure of predictability whilst losing
certain dynamic aspects of the language. I personally wonder whether
it's worth speculatively imposing such prescriptive measures whose
burden is on the programmer and where the programmer is likely to spend
a lot of time trying to work around them.

Paul




More information about the Python-list mailing list