functional or object-oriented?

Steve Bergman steve at rueb.com
Mon Sep 19 13:48:55 EDT 2005


beza1e1 wrote:

>I see myself shifting more and more over to the functional kind of
>coding. Could be related to the Haskell, we had to learn in CS. Now i
>was wondering, how other people use Python?
>
>With functional i mean my files mostly consist of functions and only
>rarely i use "class". The library modules seem to be mostly written the
>object-way on the other hand.
>
>If you use both paradigms. What are your criterias to choose the right
>method for a project?
>
>  
>
Here is a quote by Alex Martelli from the "Python Cookbook":

"If the packaging is in terms of objects that typically comprise state 
and behavior, you're using OOP.  Some object-oriented languages force 
you to use OOP for everything, so you end up with many object which lack 
either state or behavior.  Python, however, supports multiple 
paradigms.  While everything in Python is an object, you package things 
as OOP objects only when you want to.  Other languages try to force your 
programming style into a predefined mold for your own good, while Python 
empowers you to make and express your own design choices.

With OOP, once you have specified how an object is composed, you can 
instantiate as many objects of that kind as you need. When you don't 
want to create multiple objects, consider using other Python constructs 
such as modules."





More information about the Python-list mailing list