Inheritance structure less important in dynamic languages?

bruno at modulix onurb at xiludom.gro
Fri Jun 2 05:40:21 EDT 2006


Marvin wrote:
> Hi,
> 
> It's been claimed 

s/claimed/observed/

In Python and Ruby, class hierarchies tends to be *really* flat when
compared to Java or C++.

> that inheritance structures are less important in dynamic
> languages like Python. Why is that

Don't you guess ?-)

A very obvious point is that in a dynamically typed language,
inheritence is only about implementation - it's not used for class-based
polymorphism (subtyping).

Also, dynamic languages are usually very strong on introspection and
offer good support for automatic delegation ("DoesNotUnderstand" in
Smalltalk, __getattr__ in Python, etc), which tend to lower the use of
inheritence for "private inheritence" (ie: implementation reuse without
any subtyping semantic).

This leaves with only three real use-case for inheritence :
 * factoring common features of a set of related classes in an abstract
base class
 * specialisation of an existing class (proper subclassing),
 * mixins.

> and where can i read more about that?

"duck typing", "implied interface" and "composition/delegation" could be
good starting points for a google search.

-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'onurb at xiludom.gro'.split('@')])"



More information about the Python-list mailing list