Header imageAller au contenu principal

OCaml: the choice of discriminating hackers

Discriminating: in the first sense: 1a. Able to recognize or draw fine distinctions; perceptive. 1b. Showing careful judgment or fine taste :-)

Hacker: computer programming enthusiast, not security breaking fanatic.

Why OCaml?

I became interested, intrigued by this langage a long while back, in 2000-2002, when seeing it score rank second or third, just behind C and C++, on the computer language shootout hosted on alioth.debian.org. Never really invested a lot of time learning it before 2007-2008. It's not the easiest language for beginners, beeing a toolbox with a lot of tools, each having at least one distinctive name and functionality on it. Most peoples tends to prefer simple things, especially when it come to programming, where the overall picture, the frameworks, libraries, OS surrounding your development can quickly grow in becoming a big beast to harness.

It's not a language pushed by some big .com, with a lot of meaningless buzzwords and marketing hype, power, neither. The community is small, like a town rather than a metropolis. But rather brilliant. When you come from purely imperative programming, you need some times to bend your mind to another school of thought about designing a piece of (functional programming) code, the community has always be kind, supportive with me along this journey.

I've just spent one day learning and putting my first javascript project. Both languages could be seen as beeing on some opposite. Javascript has a simple, if not loose type system. It's easy getting into the stuff, it's also easy to sit in front of your computer for some stupid, unseen mistake during 4h, without catching it, and despite the very good firebug or log4javascript debugging helpers.

Ocaml has amongst the strongest type systems out there, appart from languages with solely academical, scarce communities. The result is plain simple: productivity. You will still spend some time pulling your hairs, but only for the first 1000 lines of codes. After that, some kind of light bulb turn on in your head, you've climbed some tall staircase, become acquainted with the langage, and won't find you in front of a screen pulling your hairs for an afternoon, at least not in the same way loosely typed language force you to do so. The compiler will yale at you instead of you screaming then crying in desperation.

Strong static typing has really a productive, or at least a frustration prevention advantage. This link also relate the size of source code needed to accomplish a task in various languages to the wall time for the compiled executable to perform the benchmark. This blog page is written by another ocaml enthusiast. Maybe it's a bit biased, but not to the point of changing my mind.

Despite its relatively small community, it has some big achievements:

Microsoft has developed a set of tools in OCaml, to analyse source code of device drivers provided by third parties. This was started between Windows98 and WindowsXP.

EADS/Airbus use a tool named Scade, not unlike some simulink on steroïd, written in big part in OCaml, to generate verified C or ADA code for avionics.

FFTW, Fastest Fourier Transform in the West, awarded 1999 J. H. Wilkinson Prize for Numerical Software, has it's code generation core written in OCaml.

Meta use it for typing PHP or PHP-like code and for translating PHP code to C++, see [1].

Jane Street, now a very big player in ETF trading has all its software stack written in OCaml, see [1].

Tezos has all its blockchain stack in OCaml.

Etc...

Overall, you jump in the Lisp/ML family of languages by learning Objective Caml, while most imperatives languages seems to descend from the Algol60/C family strain, both beeing very different, you definitively lack programming culture without embrassing both at some point in your (computer guy) life.

Beginner resources

  1. A must read: Toolkits for the Mind by MIT Technology Review.
  2. (Another) Why Ocaml?
  3. Why Haskell?, an excellent intro to pure functional programming, for which everything explained about Haskell apply to OCaml except for type classes.
  4. Cornell's CS3110 is a brilliant introductory level course about OCaml.
  5. O'Reilly has published a book named Developing Applications With Objective Caml, which is now available freely in electronic form (PDF, HTML).
  6. Another, newer, non-free book, Real World OCaml.
  7. An OCaml MOOC: Introduction to functional programming in OCaml.
  8. PLEAC Ocaml.
  9. The OCaml community forum.
  10. A brief history of OCaml.
  11. An interview with Robin Milner, the father on ML, OCaml beeing a descendant of ML.

Commentaires