Re:Rich Hickey on Functors in C++ (1994)
by tptacek on Tuesday July 17, 2012 @12:48PM
(#4256555)
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.
Re:Rich Hickey on Functors in C++ (1994)
by ScottBurson on Tuesday July 17, 2012 @02:43PM
(#4257172)
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.
Re:Rich Hickey on Functors in C++ (1994)
by scott_s on Tuesday July 17, 2012 @03:42PM
(#4257474)
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.
Re:Rich Hickey on Functors in C++ (1994)
by beatbrokedown on Tuesday July 17, 2012 @07:35PM
(#4258508)
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.
Re:Rich Hickey on Functors in C++ (1994)
by thought_alarm on Tuesday July 17, 2012 @02:18PM
(#4257013)
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.
Re:Rich Hickey on Functors in C++ (1994)
by spacemanaki on Tuesday July 17, 2012 @05:16PM
(#4257931)
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).
Re:Rich Hickey on Functors in C++ (1994)
by jamesaguilar on Tuesday July 17, 2012 @02:01PM
(#4256906)
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++.
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.
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.
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.