Posts Tagged ‘programming’

Beginning Functional Programming

Tuesday, October 20th, 2009

Warning: Geekspeak ahead.

I’ve been wanting to learn a functional programming (FP) language for quite a while now.

Ruby being my current fav programming language while also being malleable to FP, I thought I will dabble with some FP in Ruby. But that was not to be. While Ruby does have some basic features like closures that are necessary for FP (although it does not boast of a a lot of clarity), one has to go through a lot of hooplas to achieve immutability — the language offers no assistance here. The following video provides a good overview of what it takes to do FP using Ruby: Better Ruby through Functional Programming by Dean Wampler.

With Ruby out, I now needed a language that embraced FP wholeheartedly. And there is no dearth of choices here; see the Functional Languages category on Wikipedia. I decided to narrow down the list by picking up the more popular and/or adopted languages. This left me with Clojure, Common Lisp, Erlang, F Sharp, Haskell and Scala (but many don’t seem to consider Scala to be truly functional). That’s still too many languages. But the list is small enough that I could learn enough about each of these languages to be able to pick one that I want to learn right now.

Clojure: Lisp dialect, dynamically typed, runs on JVM (and embraces it; implying that any Java library can be used with Clojure with little extra effort), great community. Moreover, it is embraced by my company (one of our very important backend platforms is written mostly in Clojure). More on Clojure later.

Common Lisp: The oldest of them all, dynamically typed, really cool. But too many parens for my liking!

Erlang: Runs on its own rock solid concurrent runtime system, offers distributed concurrency for free, dynamically typed, allows hot swapping and…

Meanwhile, back at Ericsson, some Erlang-based products that were already in progress when the “ban” went into effect came to market, including the AXD 301, an ATM switch with 99.9999999 percent reliability (9 nines, or 31 ms. downtime a year!), which has captured 11% of the world market. The AXD 301 system includes 1.7 million lines of Erlang: This isn’t just some academic language.

(from: Erlang in; emphasis mine.)

F Sharp: Runs on the CLR (.NET Framework).

Haskell: Pure FP language, static typing.

Scala: Runs on JVM, static typing. Very complicated type system, from what I hear.

The above is obviously not a very thorough overview of the languages. It was not my intention to develop an overview at all; I just gathered enough information to be able to make a decision.

I like dynamic typing, working on Linux. My company’s main platform is the JVM. I mostly write Information Retrieval (IR) software and a lot of IR libraries are in Java. Clojure!

But I also like Erlang. I’ll get to it after I have tamed Clojure. And I also want to learn R programming language so that I can implement statistical algorithms with ease.

But what’s the point of this blog post? Nothing. I plan to blog a bit about FP in general and Clojure in particular and thought that it would be nice to provide some context. Also, I wanted to document at least part of the decision making process I have been through for picking up Clojure.