Ralf Lammel: Stop dysfunctional programming

40 years after the invention of OO, I am ready to appreciate objects quite a bit because I can use them in combination with functional programming. Naturally, I call this mix functional OO programming. (I don’t quite count functional objects in C++ or ‘functors’ in Java, a misnomer BTW, as functional programming.)

Ralf lists several of his papers that apply the notion of functional OO programming. He also shares his wish list for future versions of C#.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

[OT] Terminology defense

I don't agree that the term "functor" used in the C++ and Java sense is a misnomer. It's simply a different usage of a term, in a different context. The way the term is used in category theory and functional programming is itself a "misnomer" compared to Carnap's original usage of the term. Carnap used the term to mean a sign representing certain kinds of function (definition), which parallels the way in which C++ & Java functors are abstractions of a function.

Quality of the post questionable

I fail to see how programming with stateless C++ function objects would be any different than functional programming. Can anyone shed any light on this claim?

C#, not C++?

Which claim? The post seems to mainly be saying that in C#, specifically v3.0, the OO features can be used in conjunction with functional programming (and/or C#'s functional features) to write code in various non-dysfunctional styles. It also list some things that C# needs in order to provide better expressivity in this area.

I am refering to this

I am refering to this claim:

I don’t quite count functional objects in C++ ... as functional programming

Shall I compare thee...

Ah. I think he's just referring to the usual distinction between whether a language really supports a paradigm explicitly, or whether it's possible to use the language to fake the paradigm.

Programming in C++ with functional objects is different from traditional functional programming in quite a few ways, most of which are not an improvement. You're essentially manually constructing closures from objects, which tends to be cumbersome, i.e. less expressive. Abstraction leakage is common - features that would normally be below the language surface in a functional language are exposed in C++. You can do a lot of things with classes and/or templates etc. to try to encapsulate functional programming features, but in the end you still end up needing fairly deep knowledge of how it all works under the hood in order to use it effectively.

Programming with some of the libraries which do this kind of thing, like Boost.Lambda, bears similarities to programming in an intermediate language rather than a source language, which is a clue that the paradigm is being simulated. Looking at the list of things Ralf finds lacking from C#, one could certainly come up with a longer list for C++.

In any case, I think this is all tangential to Ralf's main points, which I attempted to summarize previously.

Experience

Having used Boost.Lambda and Phoenix fairly extensively, I can second Anton's points. In particular, the frequency with which you find yourself having to delay constants and variables in those frameworks reveals the extent to which the frameworks are indeed a "shallow embedding," if you will, of the concepts into a language that is, to some extent, hostile to them.

That doesn't make then any less useful or stunning—I flat refuse to work in C++ without being able to use Boost. Spirit (and Phoenix beneath it) are especially brilliant.

It's functional programming but not the same as in Haskell or ML

C++ functors is functional programming, but due to the nature of the language, the programmer needs to do more and be aware of more things than in Haskell or ML.

I find the trade off acceptable though. C++ was not invented for FP, and it is a great benefit that it can be done even to that degree.

What goes around; comes around

Two revolutions trying to discover their roots. Is this Lisp?

Nope

Haskell...or ML.