Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Rich Hickey on Functors in C++ (1994) (tutok.sk)
65 points by Rickasaurus on July 17, 2012 | hide | past | favorite | 14 comments


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.


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.


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.


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


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


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


Even Hickey states in this article that the term comes from James Coplien. His C++ book from 1992 was what first introduced me to the concept.


I know this is true, but "Hickey functors" is what the people who introduced them to me called them.


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.


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;


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


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).


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++.


No wonder Hickey ditched C++.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: