Code Monkeyism

Programming is hard by Stephan Schmidt

Higher Order Objects

With all this talk about higher order functions: Nearly all OO programming languages support higher order objects!

(Which are objects that take other objects to perform a task)

Higher order functions might be a big “Ah” moment in FP, but the concept is really very simple and basic in OO.

Update: Dear Dzone readers, there is not much content here, because there is not much to say. OO languages support higher order objects. Thanks.

Update 2: Functions take values as parameters. Functions which take functions as parameters are called higher order functions. Objects take values as parameters. Objects which take objects as paramaters are higher order objects. As the concept is very basic in OO, people don’t talk about it.

About the author: Stephan Schmidt is currently a team manager at ImmobilienScout24 in Berlin. Stephan has been working as a head of development and CTO. He has used a lot of different technologies in the last 20 years including Java, Rails and Python. Stephans main field of interest is maintainablity and productivity in software development. Want to know more? All views are only his own.

If you did like this article but you don't want to subscribe to new articles with your reader, you can follow me on Twitter or subscribe to new posts with your email:

Comments

Dumb Founded

“Nearly all” Okay, name one that doesn’t.

I will never get this 30 seconds back.

stephan

Oh, there surely is a language which only takes primitives as parameters, and if I had written “all” then someone would have found the language and pointed it out ;-)

Matt

Regardless of whether you’re using an object-oriented or functional language, I think the idea of “verbing a verb”[1] is distinct to that of “verbing a noun”. To “verb a verb” in functional programming means higher order functions. In OO, it’s “the Strategy Pattern”; passing a plain-old object into a method is still just “verbing a noun”.

To be controversial, I’d actually argue that “verbing a verb” is a more natural concept in functional programming than in OO, because FP is “verb”-oriented, whereas OO tends to be more “noun”-centric.

[1] Cheesy nouns/verbs stuff from http://steve-yegge.blogspot.com/2006/03/execution-in-kingdom-of-nouns.html

stephan

Sorry to disagree, if we should go into the shady noun/verb analogy then objects are verb/noun hybrids while functions are verbs.

In OO this means objects are higher order objects, because they take objects (verb/noun hybrids) as arguments. Objects have 2 dimensions while functions have only one (being verbs). Objects would not be higher order objects if they would only take primitives (nouns) that hold state but do not have methods (verbs).

And sorry to not read Steve Yegge posts, those are zealot propaganda spewing posts I have no temper to read. I’m very glad he lives in dynamic land - the land of fanatics and zealots - and not in Scala land. I’m to old for that. Fanatics weren’t funny in the end of the Amiga/ST days and are even less funny today (please ingore my posts to comp.sys.amiga.advocacy ;-)

Those people have a rigid mindset with everything explained. They are opposite of what Zen calls beginners minds.

Tracy

@Rick: I think your view is actually pretty mainstream; after all “function”-al languages are based on functions (=actions -> =verbs), whereas “object”-oriented languages are based on objects (=nouns).

Just to fling a sparkler into the crowd, I don’t think that functional languages are going to be as “big” as OOP. Functional languages seem mostly oriented towards data transformation, not data representation. So yes, they’re more powerful and compact than today’s OOP languages for transforming a data set or filtering collections, but they seem kind of clumsy for (say) building a GUI. Caveat: I haven’t been following the new FP trend very closely, but I used Scheme and APL BITD. I did start to read Steve Yegge’s stuff but JFC he’s got a lot of free time on his hands…

Matt

I don’t know much about Steve Yegge, I’m afraid. I liked his verb/noun metaphors as a slightly more colourful way of talking about how state and behaviour are treated in a programming language.

You’re quite right to point out that objects bundle data together with actions on that data, and so might more accurately be considered verb/noun hybrids. I would still be rather hesitant to say that objects-calling-objects adequately corresponds to the notion of higher-order functions.

In my view, higher-order functions are the FP equivalent of the Strategy Pattern in OO. When we say an object is a strategy, we really mean we’re thinking about that object taking the role of a pure verb (even though in actual fact it could well contain state and be a verb/noun hybrid). But that an object is passed into a method does not make it, in general, a full-on strategy, even though the method might invoke behaviour on that object. In the same way, I’d argue it’s not necessarily “higher-order” in the functional-programming sense either.

I reckon “verbing a verb” is probably going to be a bit of a head-scratcher the first time you see it, regardless of OO or FP…

Leave a Reply