Monday, 28 May 2007

Vector Graphics library for OCaml

We just released a new graphics library for OCaml programmers. The Smoke Vector Graphics library provides easy-to-use, hardware-accelerated vector graphics rendered using OpenGL:

A compiled bytecode implementation of the library is freely available for download. The source code and Linux executables are provided for three demos.

As the third demo shows, our library facilitates interactivity in the conventional style of GUI programming, with callbacks invoked via events.

We are working on add-ins to provide mathematical typesetting, network visualization, graphing, charting, a new cross-platform vector GUI and securely scripted graphical web programming.

Sunday, 20 May 2007

OCaml whups Lisp on Pythagorean Triplets micro-benchmark

Giovanni Intini recently posted a great suite of programs written in C, Ruby, Erlang and Python that count the number of Pythagorean triplets (a^2 = b^2 + c^2 for integers a, b and c<n):

This micro-benchmark quickly caught the attention of programmers from various backgrounds and snowballed into a miniature language comparison.

We submitted a simple OCaml implementation that turned out to be roughly as fast as the C implementation (faster than -O2 but slower than -O3 -ffast-math) and slightly shorter:

let n = 5000
let () =
let i = ref 0 in
for c=2 to n do
for b=1 to c-1 do
let a = sqrt(float(c*c - b*b)) in
if float(truncate a) = a then incr i
print_endline (string_of_int !i)
After several days of conferring and much performance-related deliberation, the Lisp community announced their completion of a longer and slower but "more flexible" solution written in Lisp.

For a thorough introduction to high-performance computing using OCaml, read OCaml for Scientists.

Saturday, 19 May 2007

Functional programmer stole my Job

Middle-class white-collar American computer programmers are feeling the squeeze again today, and its not from Sharon in accounts.

Only months after many programmers lost their jobs when they were offshored to third world countries like Europe, it seems that programming jobs are now being stolen by a second crowd.

Gangs of ruthless functional programmers are overwhelming interviewers by listing programming languages like OCaml, Haskell and even Lisp on their CVs.

The horrifying trend is thought to have begun in Germany, with a growing number of singles citing "OCaml" among their hobbies. In the US, starving unemployed programmers were spotted on street corners holding signs saying "Will code for Food (but only in OCaml)".

The effect is being compounded by the number of employers who now regard unenlightened programmers as second-class citizens, driving a trend of employing functional programmers in the interests of productivity. The result: functional programming is the new black.

The only programmers unaffected by this revolution are the self-employed, who have known for years that functional programming offers order of magnitude improvements in development speed, maitainability, reliability and mojo.

You have to ask yourself one question: is OCaml on your CV?

The OCaml revolution

The man behind the O'Reilly book publishers, Tim O'Reilly, recently released a series of articles analysing book sales in the programming industry and, in particular, devoted one article to breakdown by programming language.

OCaml can be seen right at the bottom under the heading "Irrelevant Programming Languages". The interesting thing from our point of view is that these statistics do not include sales of our book OCaml for Scientists, which introduces professionals in science and engineering to the OCaml programming language as a high-performance tool to help them with their research.

Naturally, by diregarding profits and more prolific publications like magazines, O'Reilly's article shows O'Reilly topping the charts in terms of units sold. Although selling many units is nice, particularly for advertising, most industries are more concerned with profits. To estimate profits it is necessary to take the cost of the book into account. This changes the results drastically and, in particular, penalises O'Reilly for publishing very cheap books.

Several amazing results come from such an analysis. Firstly, Flying Frog Consultancy have long wondered how we could boost sales and compete with mainstream publishers. From these statistics, it seems that we have been beating the mainstream publishers at their own game for some time.
We even outsold Practical OCaml in Q1 2007 in terms of units sold!

Secondly, we had been wondering if OCaml is a comparatively profitable market to enter. According to these statistics, OCaml is one of the most profitable languages to choose, beating Lisp, Scheme, Haskell and even C/C++ and Python.

Thirdly, dissecting the results by profit indicates that OCaml for Scientists is in the top 5% of the world's favorite programming books. This is probably due to the fact that OCaml for Scientists received universally fantastic reviews.

Finally, the growth of the market determines whether or not we can stay. The OCaml market has shown the second largest growth of any programming language, topped only by Ruby. We have felt this ourselves, as sales of our OCaml-related products have quadrupled over the past year and continue to rise.

Overall, we are very happy with the result. So happy that we will write a very cheap introductory book on OCaml and publish it through a mainstream publisher as well as release a second edition of our best-selling book OCaml for Scientists.

We predict that the F# programming language from Microsoft Research (which is derived from OCaml) will explode in popularity over the next year, starting with the publication of Foundations of F# by Robert Pickering later this month, then Expert F# and our own F# for Scientists.

Thursday, 17 May 2007

Rigid Body Simulator

Here is a real-time 2D rigid body simulator that renders some balls bouncing around a scene using OpenGL:

The whole program is under 400 lines of OCaml and performance is excellent: the program can simulate 100 balls in real-time with sub-centisecond accuracy on my machine.