[Tutor] methods versus functions (using lists as an example)

Max Noel maxnoel_fr at yahoo.fr
Wed Oct 20 00:01:17 CEST 2004


On Oct 19, 2004, at 22:02, Jeff Shannon wrote:

> Max Noel wrote:
>
>>     It's a matter of legacy. IIRC, Python was not, in its original 
>> design, fully object-oriented. Which is why some functions haven't 
>> been implemented as base class methods yet.
>
>
> Not true.  Python is object-oriented from the ground up, and 
> everything in Python (including basic data types, functions, modules, 
> and even class definitions themselves) is an object.

	Ah. My bad. I stand corrected.

> The reason that some of these things are done as functions and some as 
> methods of list objects, is that some of the operations make sense on 
> a much wider range of things than just lists.  If you want to be able 
> to conveniently sum a sequence, you can pass that sequence to sum() 
> and everything just works.  If sum() were a method instead of a 
> function, then *every* type of sequence would have to define a sum() 
> method that would be essentially identical.  Even worse, if a 
> programmer defines his own sequence type, then he'd have to write a 
> sum() method on that custom type before it could be summed.

	You have a point there. However, I don't really see why str() and 
repr() are functions and not methods, given that you have to implement 
methods for them to work anyway.

> I don't know Ruby, but I can certainly say that I think that Python's 
> current form (using functions for generic operations and methods only 
> for type-specific operations) is far more elegant than it would be if 
> everything were forced into methods, thus requiring many classes to 
> sprout swarms of tiny, repetitious methods...

	Ruby ( http://www.ruby-lang.org/ ) is another object-oriented 
"scripting" language. I find it extremely elegant, and in fact can't 
decide which one I prefer, Ruby or Python (I'm learning both at the 
same time). Both are extremely flexible, very fun to program in, and 
produce code that's compact and easy to read.
	So far I've been getting more work done in Python, though, because 
it's been around for longer and as a result has a lot more usable 
modules than Ruby.

> But I *do* agree that Python is quite easy to get the hang of. ;)

	It is, indeed. I was getting work done just a few hours after starting 
to read Guido's tutorial on python.org.
	The same thing can be said of Ruby. However, I find Python's 
documentation vastly superior in both quantity and quality, which means 
advanced topics can be grasped more easily.

	I'm hitting a roadblock, though, when it comes to web programming with 
mod_python. The documentation I've found about it is quite terse, and 
mod_python's logic seems completely alien to me (I was expecting 
something that works exactly like CGI but faster). Are there any good 
tutorials on the subject, by the way?


-- Wild_Cat
maxnoel_fr at yahoo dot fr -- ICQ #85274019
"Look at you hacker... A pathetic creature of meat and bone, panting 
and sweating as you run through my corridors... How can you challenge a 
perfect, immortal machine?"



More information about the Tutor mailing list