Subclass sadness (was Re: [Python-Dev] PEP 285: Adding a bool type)

Gary Stephenson garys at ihug.com.au
Mon Apr 1 16:29:56 EST 2002


"Alex Martelli" <aleax at aleax.it> wrote in message
news:DlTp8.48032$S52.1614804 at news2.tin.it...

> So, it's mutability that complicates things in these cases.  The
> exponents of Functional Programming have built rather powerful
> languages around immutable objects -- immutability may not be
> as easy and comfortable to work with in practice, and it does not
> model our computer systems all that well, but it sure does remove
> certain mathematical anomalies!

Agreed.  However, even with immutability, a client of the Rectangle class
could still create instances where height == width,  and imho it would be
both useful and cool for the system to automagically recognise and promote
such instances to having a most-specific-type of square.

Whilst the geometric arguments (rectangle/square, ellipse/circle) do have an
air of artificiality about them, there are numerous instances in the real
world where things _do_ mutate over time, and belong to varying sets of
categories as a consequence of such mutation.   Given that our objects _are_
allowed to mutate their state, wouldn't it be preferable for them to
do so in more intelligent ways?  Whether such a notion is actually
implementable in the real world is an entirely different question  of course
;-)

Simple immutability is also insufficient to enable the subclass == subtype
identity [1], which seems to me to be one of the fundamental issues
underlying all this.

cheers,

gary

[1] - http://okmij.org/ftp/Computation/Subtyping/





More information about the Python-list mailing list