[Compiler-sig] Polymorphism/encapsulation in Python

John Max Skaller skaller@maxtal.com.au
Tue, 04 Apr 2000 23:20:04 +1000


Ludvig Svenonius wrote:
> 
> Many people have been singing their praises to the extreme level of
> polymorphism found in Python. Having recently migrated from Java to
> Python, however, I find myself wanting in the area. The main problem may
> still be the lack of focus on encapsulation, however (and by
> encapsulation I do not mean baby-sitting the programmer with access
> modifiers like C++'s 'private').
> 
> Even as a Java programmer, I can certainly praise Python's support for
> multiple inheritance. Java's all the less for not having it. However,
> Java's facility for interfaces is a pure blessing, and I lack a
> counterpart for it in Python.

	Please make up you mind.
First you call encapsulation 'baby sitting', then you praise
interfaces, which are precisely what encapsulation provides.

> Java's interfaces were designed as a replacement for multiple
> inheritance. The lack of support for multiple inheritance sometimes
> makes design in Java grossly unintuitive, however. 

	Object orientation is what makes
Java counter-intuitive. Python, in many ways, is NOT restricted by
a static type system, and therefore not restricted by a broken
one like Java's. Instead, python programming is based on notions of
protocols, such as 'sequence', where a mix of lightweight functional,
procedural, and object oriented programming techniques coupled with
dynamic typing, provide highly flexible notions of interfaces,
not represented in the language (as they are in Java, Eiffel,
and typically in C++ as well).

	One would hope for a decent static type system to be invented
which can assist in typing such a protocol driven system,
but it is not easy, and Python programmers prefer to live with notional
interfaces and documentation. Note that a synthesis involving optional
static typing is being worked on. 

	In many senses, java is a lousy compromise. It doesn't
have the high performance of C++, and it is just as hard to port
serious systems as any other language. It is slightly simpler
than C++, but not nearly as easy to use as python.

	java does have one advantage though: a serious GUI (Swing).
If there is a reason for using Java, that is it. It's a mess. But it
can do a lot more than Tk, and is more stable tham GTK.

-- 
John (Max) Skaller, mailto:skaller@maxtal.com.au
10/1 Toxteth Rd Glebe NSW 2037 Australia voice: 61-2-9660-0850
checkout Vyper http://Vyper.sourceforge.net
download Interscript http://Interscript.sourceforge.net