Favorite languages, why so great? and why not so much?

About my favorite languages, I actually have 2 favorite languages

  • Ruby: for all scripting and making quick apps.
  • Clojure: for development.

Why Ruby is great

  1. The language was designed for programmer use, you can see that from the api which is totally intuitive.
  2. Lots of libraries, my favorite is Sinatra which lets you build quick and dirty web apps and the other is Sequel.
  3. I wrote a blog post on how to delete RFC-822 in compatible emails (if you are a developer using linux and your company uses Outlook you know what I am talking about), this is a simple example of how I have used Ruby to make quick and dirty scripts.

I have used Ruby numerous times to write scripts to fix production data, correct files, and to generate complex reports. I have used Sinatra with Google Charts to make web apps that can show load times, server status ….

Why Ruby is not so great

  1. Not really meant for performance, recent years there is a push to develop a virtual machine for Ruby but it is still not anywhere close to C/Java performance.
  2. Rails is a pain to deploy, Heroku takes away the pain but what do you do if you have to deploy internally ? I personally have 2 apps on Heroku one of which is

Why Clojure is great
I have been on a quest to learn a functional programming language for the past 3 years, I have read the Erlang book (please see the various posts I wrote about Erlang here). Erlang is a fine language but I lost interest in it after I could not find a single good library that can connect Erlang to Oracle. The problem, there are too few 3rd party libraries. The next language I looked at was Haskell, lots of libraries and seems to be good at performance on the surface, problem I see is acceptance by business, where most of the code is in Java. Then I found Clojure and fell in love with it.

  1. It is just another DSL for the JVM, if you provide type hints the code generated will be the same as what Java would (can easily sneak it in).
  2. Totally embraces the JVM unlike JRuby.
  3. The author Rich Hickey has done a lot to reduce the pain points of lisp.
  4. Finally a language that frees you mind of OOP ( Have you ever noticed how much time you spend in trying to achieve the best object model when a simple one would do ? and for what ? the customers don’t care as long as it works, the computers sure don’t care as long it is 0s and 1s)
  5. Code is so concise and elegant.

Why Clojure is not great.

  1. It has been called as the language with the steepest learning curve on the JVM, I tend to agree with it.
  2. Unlike Scala you have no wiggle room, it is either functional code or nothing ( I like this feature actually).
  3. Debugging is a major pain point. (Though there has been improvement with the latest clojure-swank).

I have written many posts on Clojure on my blog you can see them here. In the most recent post I show you one can parse a one million record file in less than 15 seconds with clojure.


Loving Clojure

I seem to be liking Clojure …

Let me backup a bit, in the last couple of weeks I have been debating between picking up Scala or Clojure (don’t get me wrong Ruby is still my favorite).

I always wanted to pick up a functional programming language so I dabbled a bit with Erlang and Haskell, liked Haskell a lot but without much practice it kind of died (sad times)  and Scala seems too much like Java, yeah I know it seems to have a bigger crowd than Clojure and there are a lot of big names behind it.

Maybe that’s exactly why I choose Clojure (since its the underdog), or cause it is different enough from Java or simply cause it has a better syntax and seems more elegant (apparently Clojure has better integration with Java, don’t quote me on it), anyways I decided to learn Clojure.

Peepcode has a nice screen-cast to get you started off on Clojure. If you are on the Mac there is a nice bundle for TextMate and anywhere else Netbeans with the enclojure plugin seems to be the best.

On a side note it seems more and more that Netbeans has the latest and greatest plugins for everything, then comes IntelliJ and finally eclipse, what’s going on with eclipse ? has it reached its peak and now it will start dropping off ? but on the flip side there seems to be more and more apps built on top of the Eclipse RCP like Xmind, so is Eclipse no longer going to be the leader of the IDE and just become a platform for building RCPs. This of course depends  on what Oracle is going to do with NetBeans, I really hope they give the same amount of love to NetBeans as Sun did.

Ok getting back to Clojure, don’t get your panties in a bunch when you see all those parenthesis, it is just the layout that is shocking, indent it well and it is no more than what you are used to.

Here’s an example

(defn fac
"Returns the factorial of n, which must be a positive integer."
(if (= n 1)
(* n (fac (- n 1)))

Is same as

(defn fac [n] (if (= n 1) 1 (* n (fac (- n 1)))))

But the first one is a lot more easier on the eyes (even brain?) than the second one. Most examples that you see look like the second one and it frightens people, don’t let that stop you take my word and go for it.

Clojure seems to be very easy to pick up, things seem very intuitive, like the other day I was wondering, how to return a default value from a map if the key is not found and there is was right there in the api.

(map key default-value)

So simple! I was easily able to extend the examples that came with the peepcode screencast. Anyways I have started on this path, let’s see where it goes.

Update 2009/12/03

– Looked at the Clojure source code, looks squeaky clean, I applied to become a member so that I can expand on the test coverage, hopefully they will accept me.

-It is (load-file “hello.clj”) and not load-file “hello.clj” , I keep forgetting that and after a few mins I realize it.


Erlang Blues I

So yesterday I had this bright idea to connect to MySql using Erlang, so in order to do this there seems to be two options one is to use a native interface completely written in Erlang or use ODBC . So I tried to use the native interface first.

There seems to be no documentation on how to use this, I finally found a blog with some so I gave it a try, apparently it only works if there is a password, if your password is null it will not. Frustrated I pulled out the source of the implementation, with the idea that I could somehow mess with it enough to get it to work, but the Makefile does not work. It was already 1 in the morning so I just gave up.

The second option is to use ODBC, but if I am reading this correctly you have to get erlang from the source and compile it with MySql ODBC drivers in order for this to work ! I had compiled Erlang on my computer last week, but I have no clue as to what ODBC driver I had used to compile. And too lazy to do it all over again.

Maybe I am doing something stupid here, maybe erlang is not really meant to be talking to traditional relation databases, after all once you start connecting Erlang to Mysql will it really be parallel ?   Maybe I should be extracting all the data into Mnesia.


How does Erlang Fare ?

Don Stewart recently wrote a blog comparing the time it took to compute Fibonacci numbers in Ruby, Python and Haskell, according to his results Haskell blew away the competition.

Here are HIS results

Ruby (1.8.5) 64.26s
Python (2.4) 25.16s
Haskell (GHC 6.8) 0.48s
Parallel Haskell (GHC 6.8) 0.42s

Since I am learning Erlang I wanted to see how Erlang does (please note I am a Erlang newbie) so here goes !

The Code


fib(0) -> 0;
fib(1) -> 1;
fib(N) -> fib(N-1) + fib(N-2).

for(N,N) -> [fib(N)];
for(I,N) -> [fib(I)|for(I+1,N)].

start() -> timer:tc(?MODULE,for,[1,35]).

And the results


That is 3.02 seconds, though not as good as Haskell, it still blew away Ruby and Python. Hey Erlang gurus out there is there any way we can seed this up ?


YAY I finally got OtpErlang.jar

It’s the small things in life that make you happy !! As you know I have Ubuntu 7.10 and I installed erlang using ‘apt-get install erlang’. Unfortunately this style will not install Jinterface libraries. So the only way we can get it is by actually downloading the erlang source and building it yourself.

  1. Download the source from here
  2. Make sure you have all these libraries installed (use apt-get install ) # gcc
    libssl-dev, m4, libncurses5-dev, g++, openssl, gcc, java-gcj-compat, java-gcj-compat-dev, make, unixodbc-dev
  3. Make sure you have Java installed and have the JAVA_HOME variable set up in your profile.
  4. Do a ‘./configure’ followed by a ‘make’ and ‘sudo make install’

Many thanks to the following 2 links
Ethical Hacker