Thursday, December 06, 2007

Object Oriented Programming and Functional Programming as inverse of each other

While listening to John Harrop on .NET Rocks!, I noted something he said which seems quite illuminating to me.

I'm going to paraphrase here, but this is my distillation. OO and FP are basically inverse to one another:
  • OO takes a problem and breaks it down by actors. You end up portioning functionality into all the various methods of the classes. If a group of objects all need to implement the same function, you put that in an interface.
  • FP takes a problem and breaks it down by actions. Then you model your actors (the class hierarchy from OO) with a single data type (as in a tree). You pattern match over the data, and functions do different things based on the match - the type of actor.
On oversimplification to be sure, but it sure seemed to turn on a light bulb in my head. BTW, I suspect that F# has a very bright future. I can foresee even 80%ers like me making use of it given a problem that lends itself to FP. Especially since it can play with other .NET assemblies written using traditional OO languages.

No comments: