I have been caught at odds when asked about some of the key differences between Object Oriented Programming and Functional Programming. In fact I’ve felt somewhat like a fraud, in that I regularly work in both paradigms. I often keep in mind the many of the precepts of functional design in the methods of objects I am creating.
So, I was looking to see what others had to say on FOOP (Functional Object Oriented Programming - or perhaps POOF “Programming Object Oriented Functionally”?) and I came across a post on Lambda the Ultimate which let me know I am not alone.
This lead me on to further investigations on the questions I was pondering such as where the different types of programming work - and when they don’t. A good synopsis of this started on Stack Exchange of course... These readings exposed me to a key nub of the problem - concisely stated, which has the name of “The Expression Problem”.
The expression problem is well stated in the best answer in the stack exchange post:
- Object-oriented languages are good when you have a fixed set of operations on things, and as your code evolves, you primarily add new things. This can be accomplished by adding new classes which implement existing methods, and the existing classes are left alone.
- Functional languages are good when you have a fixed set of things, and as your code evolves, you primarily add new operations on existing things. This can be accomplished by adding new functions which compute with existing data types, and the existing functions are left alone.
A look at the expression problem in detail with some ideas towards solutions is nicel addressed in Eli Bendersky’s blog post . His post seems to fit well with the some of the original literature on the problem
This bit of diversionary reading has me puzzling over some recent designs in C#, and I am also thinking of solution to the expression problem in JavaScript (where I am not even convinced I can call it a problem).
Comments