*
The moose likes Clojure and the fly likes Clojure vs. OO/Functional hybrid Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Languages » Clojure
Bookmark "Clojure vs. OO/Functional hybrid" Watch "Clojure vs. OO/Functional hybrid" New topic
Author

Clojure vs. OO/Functional hybrid

Barry Andrews
Ranch Hand

Joined: Sep 05, 2000
Posts: 523

What type of project would make one consider choosing Clojure over any other OO/Functional programming hybrid? In my experience any project can benefit from using both programming paradigms, which plenty of languages have nowadays.
Is there any type of project that is best suited for an implementation solely in Clojure?
Amit Rathore
author
Greenhorn

Joined: May 08, 2011
Posts: 20

First of all, let me (respectfully) challenge your differentiation of the two paradigms. Consider this blog post: A Silly Object System for Clojure

It shows most of Java's OO mechanisms implemented in about 40 lines of Clojure.

Functional programming, especially with LISP (or Clojure) transcends Object Oriented programming. When you take Clojure's lexical closures, multi-methods, first-class functions, the macro system, immutable data-structures and the STM, you can write code that doesn't suffer from a lot of problems actually caused by typical implementations of "object-oriented" languages. I like to think of this quote by Alan Kay - "I invented the term Object-Oriented and I can tell you I did not have C++ in mind".

In short, OO is probably not what most people think it is... and the functional paradigm, especially when combined with all the other features of a language such as Clojure, actually delivers a lot more capability.
Barry Andrews
Ranch Hand

Joined: Sep 05, 2000
Posts: 523

Thanks for the response. I'm not buying the one shoe fits all horses mentality. There must be some type of projects in particular that would be best suited for Clojure. I get that you can have OO concepts in Clojure, but it sounds like the idea is to solve problems in a different way using all functional programming? I just can't imagine modeling the world in software without OO concepts.
Amit Rathore
author
Greenhorn

Joined: May 08, 2011
Posts: 20

My point wasn't that one size fits all, but that the functional paradigm transcends, say OO. I also wanted to point out that it is so flexible, that you can "simulate" OO in just a few lines of code, not that you would, because that would be like saying a rifle isn't arrow-oriented.

To answer your modeling question, for instance: the functional paradigm can be applied to modeling business processes without modeling the actors (as OO does) but modeling the actions itself (functions). There's a lot more to it, of course, but it just involves a mind-shift and some practice. After all, people were building systems before OO.
Barry Andrews
Ranch Hand

Joined: Sep 05, 2000
Posts: 523

A mind shift I do agree on. I hope to explore this more in the coming months. Thanks for your insights.
 
Don't get me started about those stupid light bulbs.
 
subject: Clojure vs. OO/Functional hybrid