Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Clojure vs. OO/Functional hybrid

 
Barry Andrews
Ranch Hand
Posts: 523
C++ Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20
Clojure
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 523
C++ Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20
Clojure
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 523
C++ Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A mind shift I do agree on. I hope to explore this more in the coming months. Thanks for your insights.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic