August 6, 2013

3 new programming languages to watch

(that you've probably never heard of)

On the eve of learnxinyminutes.com getting TechCrunch’d, I thought I’d write about a few of my favorite languages on the site.

Learn X in Y minutes has a lot of conventional blockbusters like C and Java now, as well as old cult favorites like Haskell and Erlang, but it was the independent films — that is, languages — that received some of the earliest attention, occasionally by their creators themselves. Being the language-dabbler/compulsive HN reader that I am, I had already heard of them, but in case you haven’t, here are three cool new languages that you can stuff in your brain hole:

  • Livescript, a functional dynamic language that compiles to javascript
  • Julia, a high-performance high-level scientific computing language, and
  • Elixir, Erlang’s younger, cooler cousin.

Livescript

Livescript is a compiled-to-javascript language in the vein of CoffeeScript. Actually, it’s compatible with CoffeeScript, but it adds a bit of a Haskell flavour to it. It basically lets you write your javascript in a very functional style, including a lot of nicities. A few highlights:

Argument destructuring:

tail = ([head, ...rest]) -> rest
tail [1, 2, 3]  # => [2, 3]

Currying:

add = (left, right) --> left + right
add1 = add 1
add1 2     

Three flavours of function composition (two of which seem to be the same):

double-minus-one-a = (- 1) . (* 2)
double-minus-one-b = (* 2) >> (- 1)
double-minus-one-c = (- 1) << (* 2)

Guard-esque switch statements:

fib = (n) ->
    | n < 2 => 1
    | otherwise => fib(n-1) + fib(n-2)

Where to use it?

Since it compiles to javascript, just use it anywhere you would use JS. Livescript 1.2 was just released, and introduces even more features. So, this is a great time to check it out if you want to start writing more expressive, functional js.

Julia

Julia is a language for high-performance scientific computing. It features a high-level, python-esque syntax, and dynamic types (with type hinting). Its most impressive feature is being expressive, but also very fast. Here’s a really small recursive fibbonacci that takes just 2x as long as the C version in Julia’s own benchmark.

fib(n) = n < 2 ? n : fib(n-1) + fib(n-2)

In addition to the standard library you’d expect of any language (I/O, collections, strings etc.), Julia also comes packaged with a decent set of libraries for common scientific and engineering computing tasks, including utilities for for Signal processing, distributed computing, statistics, numerical integration, among others.

Where to use it?

Julia is a great language for doing science. Think of it as a replacement for R, Matlab, or Scipy where performance and expressiveness are needed.

Elixir

Elixir is a language targeting the Erlang VM. It aims to import many of the good parts of erlang — message passing, pattern matching, immutable values, and so on — leaving behind some of Erlang’s weirdnesses and adding new features of its own. It mostly imports Erlang’s syntax (leaving behind the line-ending punctuation), but where that is deemed too oddball inspiration is drawn from Ruby:

defmodule Math do
  def sum(a, b) do
    a + b
  end

  def square(x) do
    x * x
  end
end

Some other cool features of Elixir:

  • Protocol-based inheritance (a la Clojure)
  • Metaprogramming via macros (think Lisp, not C)
  • List comprehensions

Where to use it?

Elixir is quite mature for its age, and is under active maintenance. If you were thinking about using Erlang, consider Elixir instead. In fact, even if you already use Erlang, give Elixir a shot: both compile to the same bytecode, and so can be used interchangeably.

So there you have it. Whether you’re developing for the web, doing serious science, or building high-availability telecom services, you now have something new to try.