Book Reviews

Practical OCaml by Joshua B. Smith

ISBN-13: 978-1590596203
Publisher: Apress
Pages: 488

The OCaml language is exciting in many ways. It's a functional language with high-level features like pattern matching, garbage collection, an object system, and accompanying power tools. Most characteristically, OCaml is strongly and statically typed but uses type inference. With type inference the compiler figures out the type information itself instead of forcing the programmer to provide it. That means we get the best of two worlds; like dynamically typed languages OCaml programs are short and expressive, yet we get the blazing speed and compile-time checks of static typing.

Until recently one of the problems with adopting OCaml was the lack of literature. As Practical OCaml hit the shelfs I set my expectations high; would it do the same for OCaml as Peter Seibel did for Lisp with his excellent Practical Common Lisp ? In short, Practical OCaml turned out as a major disappointment. It's one of the worst books I've ever read. What went wrong with such a great idea?

It's obvious that Seibel's book has been a major influence for Practical OCaml. Not only is the structure similar; several of the practical chapters cover the same topics, which is a great idea (it's quite interesting to compare a Common Lisp version of a Baeysian filter with an OCaml version). However, the similarities end there. The first thing that turns me off is the writing style. Mildly put, it's disastrous. The text doesn't flow and there are terrible leaps in logic. Even more distracting are the many irrelevant concepts confusingly blended with the text.

To make matters worse, the initial chapters intended to introduce the core language are particularly badly structured. I don't know OCaml good enough to comment on the quality of the code itself, but even so I found several obvious errors and bugs in it. And it gets worse. Many code samples use constructs that haven't been introduced yet. When they do get introduced, the explanations range from weak to downright insulting. For example, early in the book the author mentions monads without any further explanation. The index has one entry for monads, page 254: A monad is purely functional, is difficult to fully understand, and is way, way beyond the scope of this discussion and this book . Truly amazing, why mention monads at all in an OCaml book? Particularly if you don't understand them well enough to explain the idea and make it relevant to the context (in this case, a discussion of pure functional languages). This style runs through the whole book; in a discussion of the type system, the author mentions parametric polymorphism and object polymorphism. Without any further explanation he writes that the subtleties of the differences are well beyond the scope of this book , which is followed by a reference to a newsgroup!

The only thing I got out of this book was a decent overview of what programming in OCaml has to offer. Besides the language itself, tools like OCaml's lex and yacc are covered. The topics may be interesting, but stay away from this book; it's simply unreadable and will do more harm than good. I simply cannot believe that Apress decided to publish this book; it's a waste of a good idea and potentially hurts the OCaml community as this book discourages any reader from learning OCaml.

Reviewed March 2008