A Python 3000 Question

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Tue Oct 30 01:11:58 CET 2007


On Mon, 29 Oct 2007 17:26:06 -0400, brad wrote:

> Rob Wolfe wrote:
> 
>> I wonder why people always complain about `len` function but never
>> about `iter` or `pprint.pprint`? :)
> 
> Not complaining. len is simple and understandable and IMO fits nicely 
> with split(), strip(), etc... that's why I used it as an example, but 
> list(), etc. could be used as examples as well:
> 
> a_string.list() instead of list(a_string)

`list()` takes any iterable and turns it into a list object.  That's a
generic operation coded *once*.  If you have `str.list()`, `tuple.list()`,
`list.list()`, `dict.list()`, `file.list()`, `MyIterableSomething.list()`,
etc. you have to code the same over and over again for all those objects.
How could that be a benefit!?

>> And to answer the question. In OO programming generic functions
>> are no less important than classes and objects.
> 
> Do they not take away from the OOness of the overall language and 
> introduce inconsistencies?

No not at all.  Why do you think so?  There are things that are best
expressed as functions.  Other allegedly more OO languages have them
too, but you need to stuff them as static methods into classes or even
uglier you see code like ``Spam().spammify(eggs)`` instead of a plain
function call.

And functions are first class objects in Python.  That sounds quite OO to
me.  You can think of a module with functions as a singleton.

Ciao,
	Marc 'BlackJack' Rintsch



More information about the Python-list mailing list