Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

Sponsored Links

Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs

Epic codefest: 7 programming languages in 7 days

Learning a new programming language isn't hard if you understand the fundamentals

  • Print
  • Feedback

Page 5 of 5

 Day seven: Clojure Granny
Developer: Shameem Mohamed Ali, who floats like a Java butterfly and stings like a Spring bee

A descendant of functional programming languages like Lisp, Clojure provides all the advantages of functional programming such as lazy initialization, dynamic binding, and macros. It also allows for integration with Java libraries, which could come in handy for operations such as date-based calculations. In addition, Clojure allows you to alter running code, making it a highly dynamic language.

I used the open source Web framework Compojure and wrote my code in Eclipse. I tried installing the Counterclockwise plug-in to run the project in Eclipse, but I had issues with the installation. The plug-in from the website seems broken, in my opinion, as it did not let me create the project in the standard directory structure that was expected for Clojure projects.

I also used Leiningen to compile and run the project, as it is the preferred way to run Clojure projects, according to users in the Clojure community. It took a while to figure out how to build a Web app using Leiningen; I had hoped to find a plug-in to build the app inside Eclipse itself. I would still prefer implementing the Web app in Java over Clojure as I feel it is easier to return dirty and impure objects from Web app coded quickly in Clojure.

I haven't done a lot of functional programming, but did learn a bit about it during the one-day exercise. I also learned about the various frameworks available for developing a Web app using Clojure before choosing Compojure.

Clojure does not have a monolithic framework analogous to Java's Spring. In fact, the Clojure community upholds a motto of "not tying components together to form a monolithic framework." Instead it provides smaller frameworks for specific functionalities, allowing users to mix and match based on their requirements. This might be a boon, but the pitfall is increased development time meshing together various frameworks.

My Clojure mentor Alan Dipert was of great help in directing me toward Leiningen over the problematic Eclipse plug-in Counterclockwise. He was also great in answering my questions along the way.

I would recommend using Clojure for functional programming rather than whipping up a Web app. Clojure has a higher learning curve for those of us more versed in object-oriented languages, which was probably the biggest drawback I saw. They are few tutorials on the Web, and the ones I was able to find seemed less informative than tutorials for other languages. There are a number of frameworks for developing Web apps in Clojure, such as Compojure, Noir, and Hiccup, but there aren't a lot of detailed tutorials aimed at using the frameworks, adding more to the learning curve.

Granny postmortem
As with any experiment, it's probably a good idea to reflect on the methodology in practice before drawing any quick conclusions about the results.

What we found was that a day was probably too aggressive. Some folks took closer to two days to deliver Granny in their respective language by the time all was said and done. Most delays were simply hitting a "snag" like a typo in a connection string parameter.

Having different people work on each language probably skews the results in terms of gauging which language would provide the "easiest" transition. Was Ruby done really quickly (matter of hours) because Brian is fast or because Rails generates most of the scaffolding for you?

Of course, people learn at different paces and have different skills. Still, it was really neat to watch this come together. I hope to follow up in the near future with more highlights on each language, especially some of the less mature ones.

Are the transition costs between two languages as difficult for a developer as people make them out to be? No. For new projects, knowing that the transition costs between two high-level languages aren't really that high might make it an easier sell to your management. Of course, "It's Monday so let's rewrite everything in Erlang" will make you seem like a Hipster Hacker at best and a clown at worst. That said, maybe your boss is open to allowing the next project be built in Ruby or Scala because you promise to at least learn the basics in a day.

Related articles

This article, "Epic codefest: 7 programming languages in 7 days," originally appeared at InfoWorld.com. Follow the latest news in programming at InfoWorld.com. For the latest business technology news, follow InfoWorld.com on Twitter.


  • Print
  • Feedback