Saturday, 1 March 2008

Book Review: OCaml for Scientists

Fabrice Marchant has kindly written and published the following review (also available in French) of the book OCaml for Scientists:

"I have read OCaml for Scientists, the work of Dr Jon Harrop, which is dedicated to the OCaml programming language. Even though science and technical computing are inherent aspects of this book this is not restrictive with the exception of a few complicated examples in the final chapter.

The OCaml language combines functional and imperative programming. It is very fast and has garbage collection. Type inference makes coding particularly concise, safe and easy. OCaml's embedded module language and object orientation form a powerful software engineering tool.

Without requiring knowledge of ML-type languages, OCaml for Scientists teaches the reader how to use OCaml for scientific computing, including the use of several powerful libraries among the examples.

There are few prerequisites for correctly following the book because the author introduces the classical concepts of programming (such as recursion) before progressively developing.

That being said, the knowledge of an imperative programming language (like C or Pascal) or a functional one (such as Lisp or Scheme) is not absolutely required but would make the book more straightforward.

An important part, at the beginning of the book, is dedicated to a proper understanding of the language itself: here one finds coverage of the functionalities offered by OCaml's many keywords, illustrated by numerous clear examples.

This book does not content itself with being only a tutorial of the language. The author shows the proper usage of the possibilities of OCaml - such as the best programming practices - and often goes further in justifying things by studying the internal representation used by the compiler.

Working side-by-side with practical examples, the clarity of the exposition of this part of the book constitutes what is probably one of the most efficient mediums offered to the beginner, to rapidly acquire an understanding of the basic language necessary to program.

Dr Harrop teaches things in such a manner that reading is always easy, even when covering non-trivial scientific subjects. The syntactic coloration, on large white pages, makes the book pleasant to open.

These two aspects work together to give an impression of clarity and simplicity.

The book, stuffed with examples, has a practical view of the different programming components comprising the OCaml system: The customisable top-level, the many compilers, the dependency visualiser and profiler, are all presented together with their usage.

The book's examples are worth a special mention. With the exception of the contents page, it is difficult to find a page which does not present several concrete examples of programming. Some of them are surprisingly elaborate.

Similarly, on the practical side: The use of certain libraries, such as "command line arguments, big arrays, vector matrix and lexing and parsing, are presented in detail.

Despite the scientific focus, the first few chapters are of general interest.
Other parts such as visualisation (with OpenGL) or lexing and parsing, are perhaps particularly useful for game designers.

In addition to OCaml for Scientists, I own "Programmation fonctionnelle, générique et objet (Une introduction avec le langage OCaml)" by Philippe Narbel. The two works complement each other, OCaml for Scientists being more concrete. To cite only the unique parts of OCaml for Scientists, it presents libraries and studies optimisation in detail.

Certainly, IMHO, a section detailing the writing of functors would have been welcome. However, studying the book gives an understanding of the language such that one can undertake substantial programming projects.

The book, preceded by a glossary, is divided into ten thick chapters:

Introduction, Program Structure, Data Structures, Numérical Analysis, Input and Output, Visualization, Optimization, Libraries, Simple Examples and Complete Examples, Bibliography, Advanced Topics and Troubleshouting.

To conclude, OCaml for Scientists is an excellent book, clear and practical, which can be used as a reference work."

No comments: