functional or object-oriented?
Bruno Desthuilliers
bdesth.quelquechose at free.quelquepart.fr
Mon Sep 19 15:58:00 EDT 2005
beza1e1 a écrit :
> 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
which is not enough to make it 'functional'.
> 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?
>
Well, I'm most from an OO background, but I think OO and FP have in
common to try to be as declarative as possible, FP by avoiding
side-effects and relying on function composition, OO by hiding
implementation and relying on polymorphic message dispatch. When it
comes to 'pure' OO languages like Python, there's no real differences
between classes, objects, functions, methods, attributes etc - they're
*all* objects. So functional programming in Python is still OO ! When
you realize that the def statement is nothing more than syntactic sugar
to instantiate a function object, you can ask yourself if using or not
using the class statement is really the question.
Now to answer your question, I don't have 'criterias to choose the right
method for a project'. I happily mix procedural, OO and FP wherever it
fits.
More information about the Python-list
mailing list