On Nov 4, 2008, at 3:44, cwyang wrote:

> So, I understand as follows:
> - OOP: keeping objects, which has states and methods.
>        methods are encapuslated to the corresponding object.
> - FP: keeping objects(or structs or variables, whatever it is called)
>       and functions on the objects.
>       functions does not encapsulated to specific objects, for some
> reasons.
>
> Other characteristics such as function as first-order data structure
> and
> enforcing functional way (discourated side effects and immutable
> variables)
> can be important, but not in modeling the world.

I think the difference is more fundamental than what you describe. On  
the other hand, I don't think that OOP and FP are contradictory.

Here is my view of things:

OOP = data abstraction. The program structure is defined by the data  
that the program works on. Important data structures are identified  
and implemented together with their associated operations as classes.

FP = algorithmic abstraction. The program structure is defined by the  
algorithms that are used. Important algorithmic patterns are  
identified and implemented as functions that take functional  
arguments, or as macros. Functional arguments make it possible to  
insert specific actions into a skeleton.

There are additional properties typically associated with OOP  
(polymorphism, inheritance, ...) and FP (referential transparency,  
immutable data structures, ...), but I think the approch to program  
structure is the aspect where the two methods differ most. On the  
other hand, there is no reason not to use both data abstraction and  
algorithmic abstraction in a program. In that sense OOP and FP are  
orthogonal and combinable.

As an illustration of the two approaches, consider a program to sort  
data. In OOP, one would define an abstract class "comparable" with a  
method "sort" that works by calling methods such as "greater" and  
"equal" implemented in concrete subclasses. In FP, one would write a  
function "sort" that takes as arguments a list of things to sort plus  
a function to do the comparisons. At the top level of the program,  
you'd see "interface comparable" in the OOP version and "function  
sort" in the FP version. A mixed OOP-FP program might call the FP  
function "sort" and pass the method "compare" of a subclass of  
"comparable" as the comparison function.

Konrad.



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to