Scala: Functional programming on the JVM
If you need the code simplicity of object-oriented hierarchies for your project but love the functional paradigm, you have several choices. If Java is your realm, Scala is the choice for you.
Scala runs on the JVM, bringing all the clean design strictures of functional programming to the Java world by delivering code that fits with the Java class specifications and links with other JAR files. If those other JAR files have side effects and other imperative nasty headaches, so be it. Your code will be clean.
The type mechanism is strongly static and the compiler does all the work to infer types. There’s no distinction between primitive types and object types because Scala wants everything to descend from one ur-object call Any. The syntax is much simpler and cleaner than Java; Scala folks call it “low ceremony.” You can leave your paragraph-long CamelCase variable names back in Java Land.
Scala offers many of the features expected of functional languages, such as lazy evaluation, tail recursion, and immutable variables, but have been modified to work with the JVM. The basic metatypes or collection variables, like linked lists or hash tables, can be either mutable or immutable. Tail recursion works with simpler examples, but not with elaborate, mutually recursive examples. The ideas are all there, even if the implementation may be limited by the JVM. Then again, it also comes with all the ubiquity of the Java platform and the deep collection of existing Java code written by the open source community. That’s not a bad trade-off for many practical problems.
If you must juggle the data in a thousand-processor cluster and have a pile of legacy Java code, Scala is a great solution.
Haskell: Functional programming, pure and simple
For more than 20 years, the academics working on functional programming have been actively developing Haskell, a language designed to encapsulate their ideas about the evils of side effects. It is one of the purer expressions of the functional programming ideal, with a careful mechanism for handling I/O channels and other unavoidable side effects. The rest of the code, though, should be perfectly functional.
The community is very active, with more than a dozen variants of Haskell waiting for you to explore. Some are stand-alone, and others are integrated with more mainstream efforts like Java (Jaskell, Frege) or Python (Scotch). Most of the names seem to be references to Scotland, a hotbed of Haskell research, or philosopher/logicians who form the intellectual provenance for many of the ideas expressed in Haskell. If you believe that your data structures will be complex and full of many types, Haskell will help you keep them straight.
Julia: Bringing speed to Python land
The world of scientific programming is filled with Python lovers who enjoy the simple syntax and the freedom to avoid thinking of gnarly details like pointers and bytes. For all its strengths, however, Python is often maddeningly slow, which can be a problem if you’re crunching large data sets as is common in the world of scientific computing. To speed up matters, many scientists turn to writing the most important routines at the core in C, which is much faster. But that saddles them with software written in two languages and is thus much harder to revise, fix, or extend.
Julia is a solution to this complexity. Its creators took the clean syntax adored by Python programmers and tweaked it so that the code can be compiled in the background. That way, you can set up a notebook or an interactive session like with Python, but any code you create will be compiled immediately.
The guts of Julia are fascinating. They provide a powerful type inference engine that can help ensure faster code. If you enjoy metaprogramming, the language is flexible enough to be extended. The most valuable additions, however, may be Julia’s simple mechanisms for distributing parallel algorithms across a cluster. A number of serious libraries already tackle many of the most common numerical algorithms for data analysis.
The best news, though, may be the high speeds. Many basic benchmarks run 30 times faster than Python and often run a bit faster than C code. If you have too much data but enjoy Python’s syntax, Julia is the next language to learn.