Saturday, October 13, 2007

Deferring evaluation

One of the first cool features of the Scala language that struck me is the ability to defer the evaluation of a function argument simply by changing the type of the function definition.

In essence, you simply take an existing type declaration for a function argument of a given type:

def succ(x: Int): Int = 1+x

and insert => to defer the evaluation of the expression:

def succ(x: => Int): Int = 1+x

Now, evaluation of the expression passed to succ is deferred and each reference to x in the body of the function succ actually evaluates the given expression.

Kent Tong recently gave a good practical example of how this can be used to defer the computation of debug expressions. This addresses a common problem where computing debug strings too eagerly can slow down a whole application significantly even if the debug strings are never logged!

Sunday, October 7, 2007

Flying Frog move into Scala market

We posted a note that our ray tracer had been ported to Scala and asked if anyone would like a new book Scala for Scientists following on from our OCaml for Scientists and new F# for Scientists titles. The response was tremendous!

Needless to say, we're now diversifying into the Scala market and you'll most likely see a lot of free example demos and commercial Scala/Java products from us in the near future.

For us, the most interesting thing about Scala is the fact that it builds upon the Java legacy. Our area of expertise is technical computing (how computers can benefit scientists and engineers). We started out with C++ but quickly discovered the benefits of modern statically-typed functional programming languages of the ML family (primarily OCaml).

However, these languages are obscure compared to mainstream languages like C++, Java and even (in technical computing) good old Fortran. One obvious problem with this is lack of libraries. OCaml has a lot of libraries and, compared to mainstream languages, the libraries that exist for OCaml are of incredibly high quality. However, the world keeps changing and OCaml lacks libraries to deal with many recent inventions like web services (SOAP, UDDI, WSDL and so on).

The easiest solution to this problem is to build a new generation of functional programming languages on top of existing platforms that already have big user bases. Fortunately, efforts are underway to bring state-of-the-art programming languages to both of the major cross-language platforms. The F# programming language from a team led by Don Syme at Microsoft Research targets their .NET platform and the Scala programming language from an academic group led by Martin Odersky at the EPFL in Switzerland targets the JVM.

The .NET platform is a wonderful thing: designed to support multiple languages (the Common Language Run-time) and often more efficient than the JVM. However, for all intents and purposes, .NET means Windows only. Microsoft have the functional programming on .NET market pinned down with F# and they just switched on the development afterburners (expect a major announcement soon!).

That leaves the JVM. Java is the primary language for the JVM and has shot to super-stardom in recent years, becoming not only a dominant force in web programming but also technical computing and many other areas. Java is now widely used by scientists and engineers and is a particular favourite among bioinformaticians, not least because the JVM runs on Linux, Mac OS X and Windows. This is of particular interest to us because dozens of bioinformatics institutes across the world have bought our book OCaml for Scientists. Although the JVM was not originally designed to support multiple languages, several major new languages have been built on top of the JVM (e.g. JRuby and Groovy) and there has been much discussion about augmenting the platform with features (like tail recursion) to help the development of new languages.

We have no doubt that F# is about to make serious inroads into technical computing on the Windows platform, and will even draw in users from other platforms. However, if the purpose of building upon an existing framework is to exploit its popularity, then we must consider how popular the dominant languages for each framework are. In general, the popularity of Java and C# is quite close, with most users working on web programming, database programming and GUI application development. However, among technical users, Java is vastly more popular than the whole of .NET. In fact, the number of technical users of C# is similar to the number of technical users of OCaml. We learned this the hard way by releasing an FFT library for .NET before surveying the market properly, only to discover that it is only as popular as our Visualization library for F#.

F# is set to explode in popularity over the next three years and the vast majority of technical users on the Windows platform will migrate to F#, followed by many non-technical users. Scala has the disadvantages of a much smaller development group and no advertising budget but the advantage of growing on top of a vastly more popular platform. So we believe that both projects are about to reshape the programming language landscape. We just completed F# for Scientists. Now its time for Scala for Scientists!