Functions vs OOP

William Gill noreply at domain.invalid
Sat Sep 3 23:09:03 CEST 2011


On 9/3/2011 12:29 PM, MRAB wrote:
> I think you mean "complementary". :-)
How polite of you to point out my spelling deficiency.  I guess 
shouldn't be watching football while typing (I'm sure the beer didn't 
help either).

> I think that it's all about "state".
>
> In functional programming, there's no state; a function's result
> depends solely on its arguments, so it will always return the same
> result for the same given arguments.
>
> In OOP, on the other hand, an object often has a state; a method may
> return a different result each time it's called, even for the same
> given arguments.

I think you mean "it [sic, a function] will "return the same result for 
the same given values..."

     x=1
     y= myFn(x)

will return the same result as

     y= myFn(1)

A method may use an attribute as an implicit argument, and that 
attribute's value change, just like the value of x (above) may change. 
It may or may not return anything (it may just modify an attribute).

The question wasn't about encapsulation, it was about programming 
paradigms, and if they conflict.

As was pointed out elsewhere, I may have just confused "functional 
programming" with "programming using functions".





More information about the Python-list mailing list