Functions vs OOP

William Gill noreply at domain.invalid
Mon Sep 5 13:45:25 EDT 2011


On 9/4/2011 9:13 AM, rusi wrote:
> On Sep 3, 9:15 pm, William Gill<nore... at domain.invalid>  wrote:
>> During some recent research, and re-familiarization with Python, I came
>> across documentation that suggests that programming using functions, and
>> programming using objects were somehow opposing techniques.
>
> Staying with (for the moment) the suggestion that OO-P and F-P are
> complementary, I believe it is worthwhile to distinguish syntactic OO-
> P vs F-P from semantic OO-P vs F-P.
>
> Syntactically: f(x) is functional x.f() is object oriented.
> Semantically if f's return value depends only on x ie does not depend
> on state it is functional (in the math sense) -- the jargon is that f
> is referentially transparent.

Not to split hairs, but syntactically f(x) is a function in many 
programming paradigms.

As I understand it functional programming places specific requirements 
on functions, i.e.referential transparency.  So f(x) may or may not be 
"functional".

x.f() is also a function, but it is a member of the object x, is 
referred to as a 'method' of x, and uses the syntactical "dot" notation 
object"dot"function for identification.

> Referential opaqueness is usually such a source of problems that it
> turns out good to contain the problem somewhat -- hence the wish for
> encapsulation.
>
> One can find in the python library itself all 4 combinations:
> syntactically and semantically OO : sort
> syntactically and semantically FP: sorted
> syntactically OO semantically FP: join




More information about the Python-list mailing list