language design question

Sébastien Boisgérault Sebastien.Boisgerault at gmail.com
Mon Jul 10 11:54:31 EDT 2006


Steven Bethard a écrit :

> The advantage of a functional form over a method shows up when you write
> a function that works on a variety of different types. Below are
> implementations of "list()", "sorted()" and "join()" that work on any
> iterable and only need to be defined once::
>
> [... skipped ...]
>
> Now, by providing these as functions, I only have to write them once,
> and they work on *any* iterable, including some container object that
> you invent tomorrow.

Yep. Rubyphiles would probably define these 3 methods in a "module"
Iterable and "mix" it in their brand new container classes.
These classes then automatically have list, sorted and join *as
methods*.

Guess you could use this kind of trick in Python if you can live with
heavy *and* implicit surgery of the inheritance chain ;)

Cheers,

SB




More information about the Python-list mailing list