(Note, long after I wrote this entry: I think OCaml has some fairly fundamental problems that keep it from being a first choice for server-side development. If I were to use it for anything, it would be as a substitute for C++ in delivering client-side executable/GUI programs, e.g. for Windows systems. And I still think it's a really cool language.)

I wasn't really planning on writing another blog entry on OCaml, but... gosh. And I use the word "gosh" advisedly. I'm at a loss for words here.

Sure, yes, OCaml generates lightning-fast executables, with much, much better code than C++, apparently regardless of which C++ compiler or platform you're comparing it with.

And yeah, OCaml is pretty much the most expressive language I've ever used, maybe more expressive even than Ruby and Lisp, and I'm still not finished learning the more exotic features like Functors.

Yes, yes, it supports OO, imperative, functional and logic programming, seamlessly intermixed, so you can program a solution in any style appropriate to the problem at hand. We all know that.

And it's no big deal that there's a perl4caml module that lets you use *any* CPAN module seamlessly in your OCaml program, and a mod_ocaml for Apache, etc. etc.

And most people probably don't care that it has an exceptionally high-quality Emacs mode, and an interactive intepreter (as well as a high-performance native-code compiler), and some great libraries (including graphics bindings for various UI toolkits).

It probably doesn't even matter that it has full C++ bindings for those times when you really need to make calls into code written in a slower language.

You might not even care that it comes with a rich set of libraries that rivals the Java platform APIs in comprehensiveness and usability. Or that it's been ported to .NET (and soon, the JVM).

But come on... you have to stop and take notice at the OCaml replay debugger, which can step backwards through time as well as forwards. You don't see that every day.

At first I was a bit amazed at how much support there is for real-world development in OCaml - as far as I can tell, it's got everything you'd find in any other mainstream language, with a relatively smaller user community.

But now I think it's not amazing at all; it's a natural consequence of the fact that it's simply a superior language. It stands to reason that if you have a language that really does live up to the promise of making people (say) 10 times as productive as the other languages out there, then it will only take 1/10th the people (or time) to reproduce the functionality that's been created for other languages. And it's been around for a decade - much longer if you consider that it was derived from ML, which started in the late 1980s.

All that hoity-toity stuff aside, though: nobody really cares about most of that when they're actually using a language. To learn a new language takes a real commitment, especially if it's not from the Algol imperative family (as are C, C++, Java and Perl). What really matters is whether you can get stuff done, and whether the language feels "comfortable" when you're using it. I can't speak for anyone else, of course, but in my experience with it so far, I find it a real pleasure to use - and I would even if it didn't have such incredible runtime performance.

It was one of the more difficult languages to pick up, and took some serious digging and head-scratching before I started to write in it naturally. But once you get past the syntax, and work with it for a while, I think you'll find that it's a really comfortable language. There are LOTS of ways to do things; you can program in a Lisp-y style if you like, or a Perl-y style, or just about any other style. But when you finally get your stuff past the compiler, it usually works correctly the first time. The only runtime bugs I've ever had were incorrectly specified algorithms. I'm really starting to like having code that works the first time - more often, in fact, than in Java or other statically-typed languages I've used a lot.

If you're interested in looking at it, you should start here:

http://www.merjis.com/developers/ocaml_tutorial/

Have fun!

(Published July 02, 2004)