the blog for developers

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.

Update 3: As commented, a function is also higher order when it returns a function. “A function that takes a function as an argument, or returns a function as a result”. Same goes for higher order objects (those returning an object in a method)

You can leave a Reply here. Of course, you should follow me on twitter here.

You can share this post!
Do you want to tell others about this article? Use the social bookmark icons to submit this artice to the service of your choice. Thanks.

About the author: Stephan Schmidt has more than 15 years of internet technology experience and 10 years experience in agile. He was head of development, consultant and CTO and is a speaker, author and blog writer. He specializes in organizing and optimizing software development helping companies by increasing productivity with lean software development and agile methodologies. Want to know more? All views are only his own.
Leave a reply.

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…

Higher Order Function explained:

http://c2.com/cgi/wiki?HigherOrderFunction

Instead of taking a function as parameter, it can produce a function as result.

“A function that takes a function as an argument, or returns a function as a result.”

I’ll add this to the post.

Leave a Reply

What people wrote somewhere else:

Additional comments powered by BackType

Guide to CodeMonkeyism

Over the last 4 years I wrote many articles on this blog. To make it easier for you to find the relevant ones, I've organized them into topics.

Top 10

6 reasons why my VC funded startup did fail

Go Ahead: Next Generation Java Programming Style

Java Interview questions: Write a String Reverser

The dark side of NoSQL

7 Bad Signs not to Work for a Software Company or Startup

Is Java dead?

Scala vs. Clojure

Never, never, never use String in Java

No future for functional programming in 2008 – Scala, F# and Nu

Clojure vs Scala, Part 2

Java Developer

Is Java Dead?

Go Ahead: Next Generation Java Programming Style

Be careful with magical code

All variables in Java must be final

Never, never, never use String in Java

Bending Java: More readable code with methods that do nothing?

NoSQL Guy

NoSQL: The Dawn of Polyglot Persistence

The dark side of NoSQL

Essential storage tradeoff: Simple Reads vs. Simple Writes

Sharding destroys the goals of your relational database

The unholy legacy of databases

Startup/CTO

Development Dream Teams

6 reasons why my VC funded startup did fail

American vs. European style of Software Development

12 Things to Reduce Your Lead Time and Time to Market

The high cost of overhead when working in parallel

Essential storage tradeoff: Simple Reads vs. Simple Writes

Job Seeker

Another Good (Java) Interview Question

7 Bad Signs not to Work for a Software Company or Startup

Java Interview questions: Write a String Reverser (and use Recursion!)

Java Interview questions: Multiple Inheritance

As a Manager: What I value in developers

Top 10 Tips (+1) to Get a Pay Raise

Agilist

What Developers Need to Know About Agile

5 Practices Better to Change in Your Scrum Implementation

Scrum is not about engineering practices

ScrumMaster and ZenMaster: The joke of certification

What is Trans-Scrum?