Why Did Heroku Choose Clojure? And Why Would You?

Tuesday, July 12, 2011



Not too long ago, Salesforce, a behemoth in the CRM space, acquired Heroku, a young cloud platform for Ruby and Rails applications. Nobody was sure what Salesforce's plans were when they made the acquisition, and even now, several months later, nothing but the light of speculation shines on the matter. The official words from Heroku and Salesforce say that both companies share similar philosophies/personalities, and both share a mission to make developers' lives easier and more enjoyable. This is great! I agree that both companies do a great job at developer relations. But from a business point of view, with happy developers comes unpredictable innovations, and persuading innovation to happen in your backyard is certainly a worthwhile investment!

Since the acquisition, Heroku has made some pretty consistent and sizable strides: releasing a new version of their stack, announcing support for the hot and new node.js web server, and announcing support for Clojure. As a Ruby/Rails platform, Heroku has had neither need nor want for the JVM. However, now that it has official support for Clojure, this has changed (Clojure is JVM-based language). Because this requires them to split their attention between hosting JVM apps and Ruby apps, this latest upgrade may prove to be a significant investment by Heroku. It stands to reason, therefore, that it will now be somewhat easier for Heroku to support other JVM technologies, such as Scala or Groovy, which is exciting.

But why did Heroku adopt Clojure as their newest language, as opposed to some other language? Well, functional languages have always been on the fringe, but they have been consistently gaining in popularity. According to the TIOBE language index, functional languages have 4.4 points (of 100) of popularity. Yes, this is pretty small compared to object-oriented language's 56 points, but it also shows the greatest increase in interest of all other programming paradigms, boasting a one-year delta of +1.4 points compared to object-oriented paradigm's delta of +0.6 points.

How, then, are these minority members using functional languages, and why is it growing it popularity? According to this 2011 survey of Clojure users, 62% of its users use Clojure for web development, which is the outstanding majority, followed by math/data analysis and NoSQL programming at 42% and 27%, respectively. Note, however, that an even 50% of the respondents do not yet use Clojure at work, but rather use it as a language for hobby projects. Also note the results of the "What have been the biggest wins for you in using Clojure?" section, which shows that it is chosen not for its strong concurrency support, but because it is strong functional language. Many Lisp users have adopted Clojure because it has been chosen as the modern reincarnation of Lisp, so keep this large user-base in mind when viewing the results. Clojure users also cite their appreciation of its robust, immutable data structures, and its ability to run on the JVM.

It also paves the way for fewer bugs to be written. Because it a functional language, and hails from the Lisp family, it is a highly concise language. As a concise language, Clojure allows for high functionality in few lines of code, meaning that there are fewer lines of code on which a bug can appear. Also, because Clojure data structures are immutable, there are fewer cases in which a programmer may forget to handle unexpected input in function/method definitions, meaning fewer bugs. From my research, the general consensus of functional languages is that they allow for relatively carefree programming, and that functional apps have fewer bugs and run faster than their object-oriented counterparts.

Clojure is a relatively young language, appearing in 2007, so why should you consider shifting to a functionality language like Clojure? If you are like its other users, you would choose it because it is a fast, efficient, functional language, and because it extends the bloodlines of Lisp, which has a long academic and open source history. The survey above shows that, while it may not have a solid share of the commercial sector yet, it has a real potential to gain a larger share. It would be a great choice, for example, in which to write a high-performance, scalable web app, and web-based solutions are still surging in popularity.

I have a high interest in functional languages, and how they can be used as a means of creating more efficient and scalable code. I look forward to seeing the community grow around functional languages, such as Clojure and Scala. I'll admit that Clojure's syntax, with its many parentheses, is very intimidating at first to many developers, which is definitely a hurdle to its growth. It requires education and hands-on experience to overcome this hurdle, but once overcome, its use can produce huge gains in developer productivity and application performance.

As they stated in their acquisition vows, both Heroku and Salesforce aim to make developers' lives better and to foster innovation. By looking at Clojure as a functional language, it's pretty clear that Heroku chose to adopt it for their platform because it is a strong contender as a functional language for reasons given above.

If you're interested in trying out a functional language, I suggest you try using Clojure on Heroku - it would be a pretty great learning experience. Keep in mind, that if you happen to make something awesome, because it was written in a functional language and is in the Heroku cloud, you should have no trouble scaling your web app to meet demand when it becomes supremely popular.

No comments:

Post a Comment