Saturday, March 26, 2011

OO vs. FP

Finally, a concise and perfect resolution to the question of object oriented programming vs. functional programming, assuming the debate is even an appropriate one in the first place.  I've stuggled along with this issue myself without finding a satisfactory resolution.

Today a blog posting announced, and was echoed on Slashdot, CMU Eliminates OO Programming for Freshman [Sic.  I presume it's for more than one freshman].  In the ensuing discussion, bradley13 posts a reply that captures and resolves this issue in the most concise and accurate way I've seen.

OO is practical for lots of problems, because it makes modelling real-world data easy. However, it is not useful if you want to give students a solid understanding of the theoretical computer science. OO is fundamentally data-centric, which gets in the way of algorithmic analysis.

To give a pure view of programming, it would make sense to teach pure functional and pure logic programming.

That's it!  FP is useful for expressing and teaching algorithms!  Now, having a programming language that doesn't even include I/O makes sense.  Now I understand why colleges wanted to use FP (Scheme and such) for their introductory classes.   You can just settle into looking at the pure algorithms with the same mathematical purity as you study  2 + 3 = 5 or a proof in geometry.

That's also why FP seems so difficult to use in the real world, at least to me, in spite of well-written and -spoken arguments, and perhaps even well-documented examples, to the contrary.

On the other hand, OO is indeed well-suited for writing real programs and solving real problems.  It is imminently practical.

Now it makes sense.  The theoreticians scoff at OO while practical coders are sometimes bewildered by FP.  (Okay, it could be that only I am befuddled, and the FP proponents do keep saying that you just have to see the light).

There are some underlying themes in the discussion on Slashdot I agree with.  One is that I don't think any education program should start with OO.  I agree that a program should begin with the simplest programming environment possible   Most folks around my age, and some younger, learned FORTRAN or BASIC first.  That seemed to be a perfect introduction.   And yes, I'm well aware of the FP crowd that is shouting at this point:  FP is the epitome of purity and simplicity!

In fact, I've heard that some teaching programs are switching to Python and I think that's an excellent solution.   Python can serve in all of these roles, from a simple, BASIC-like beginner language, to a functional language for studying theory, to an immensely practical language for solving some of the most difficult  computing challenges.

To bradley13 I say, Thank you for clarifying this discussion for me in such economic terms.  Well done!