
Rich Hickey on Functors in C++ (1994) - Rickasaurus
http://www.tutok.sk/fastgl/callback.html
======
tptacek
I know everyone here knows Rich Hickey from Clojure, but I'm a C/C++
programmer from the '90s and I primarily know him for "Hickey functors", which
were the de facto standard way of doing object-oriented callbacks in C++.

Also, while I am sure they were for the time a near-optimal solution, they are
f'ing gross, so "Hickey functor" is a bit of an epithet. "Oh well, better than
Hickey functors" was a justification for a lot of Gang-of-four pattern goop in
my C++ code.

~~~
ScottBurson
The right thing is what is here being called a "bound pointer". It is actually
the correct implementation of a closure: a code pointer paired with a data
pointer, where only the code in question needs to know the type of the data
pointer.

I proposed it to Stroustrup et al. in 1992, but was ignored.

I don't recall their rationale for rejecting it, but I think time has borne me
out.

~~~
scott_s
I know from D&E that the C++ committee has a policy of only accepting new
features which had an existing implementation and first-hand accounts of using
the feature.

~~~
mkup
There was existing implementation in 90s, bound pointers were implemented in
Borland C++ Builder (__closure keyword).

~~~
scott_s
Then I think it's fair to assume the above poster was not the only person to
propose it.

~~~
ScottBurson
I probably wasn't the only one proposing it, but I have no way to know who
else might have done so.

------
beatbrokedown
Just in case anyone forgets this is from 1994(it's in the title!). Typical
modern C++ has been using this pattern for quite a while (boost::function /
boost::bind) and it is now even part of the standard (std::function /
std::bind). So don't go implementing Functor0->Functor9 yourself!

It is always nice though to see how C++ has grown after so many years and
clearly still has staying power for even new projects.

------
thought_alarm
Back in the 90s Borland extended their C++ compiler to support what he refers
to as "bound pointers", which was used with their mostly excellent Windows SDK
for C++ and Delphi.

    
    
        myButton->onClick = controller->showAboutBox;

------
eliasmacpherson
Is this in response the recent article with C++0x, Stepanov and Functors with
a nod to Haskell?

~~~
spacemanaki
I'm kinda out of my depth here, as I know next to nothing about C++, but I'm
pretty sure it's not. These functors are fundamentally different thing (first-
class function object?) from what that other article and what Haskell calls
functors (container that can be mapped over).

------
jamesaguilar
This is what I normally use. It's not as good as a language that has truly
decent support for callbacks, but it's a darn sight better than vanilla C++.

------
shizzy0
No wonder Hickey ditched C++.

