Friday, 28 September 2012

Array languages rock


As a long-time MATLAB developer, I may be biased, but: Array languages rock!

Why?

They allow the developer to express simple numerical relationships in an incredibly declarative manner. In this, they go a further than typical functional languages, by allowing you to discard the use of "zip", "map", list comprehension constructs etc.. for a variety of simple cases.

procedural < functional < array

Indeed, when one gets to the point where much of the standard library of an array language is able to accept and return collections, the developer becomes able (in many cases) to purge flow control from great swathes of the program.

As a result, one ends up with a program where control flow proceeds linearly, from top to bottom, greatly reducing the mental gymnastics that are needed to understand what the algorithm is doing, greatly improving readability, and dramatically improving productivity.

Sure, the run-time performance of MATLAB often sucks, but there is no real reason why array languages cannot be highly performant. This is why I am feeling excited about the emergence of languages like Julia, that attempt to be the best of both worlds.

These new, emerging languages excite me:

  • Go: For it's fast compile, opinionated toolset, close-to-the-metal feel, approach to object-orientation and its support for concurrency.
  • Julia: For attempting to make array programming performant.
  • Cobra: For bringing design-by-contract back into vogue.

My ideal software tool:

Designed primarily to allow academics, data scientists, mathematicians, financial engineers and other domain experts to prototype ideas quickly, it will feel a lot like MATLAB with a highly interactive development environment, excellent plotting and visualisation tools, and a large standard library filled with functions that accept and return arrays.

It will allow these prototypes to be quickly and easily brought up to production quality standards by supporting (out of the box) quality control mechanisms like strong typing, design by contract, assertions, built in static analysis, test coverage tools & continuous testing tools.

Like Go, it will compile very quickly to highly performant native binaries, support concurrency and multiprocessing out-of-the box, and be able to deploy to future production environments, which are likely to include highly heterogenous "cloud" environments as well as multicore CPU + GPU embedded systems.

Why declarative?


One of the challenges of software development is to try to identify those aspects of the system that are likely to remain constant, and those areas that are likely to change in future. These aspects are rarely specified, rarely understood, and rarely do we (as developers) get the architecture of the software right (in this respect).

Having done this, we try to make the transient, changeable aspects of the system as declarative as possible; perhaps going as far as to express them as statements declared in a configuration file.

Having done a bit of Prolog programming in the dim and distant past, my intuition is that trying to make everything declarative is a mistake; one ends up tying oneself into knots. The mental gymnastics simply are not worth it. However, splitting the program into declarative-and-non-declarative parts seems reasonable.

In fact, the idea that a a multi-paradigm approach can be used, with some parts of the system expressed in OO terms, some in functional terms, and some in declarative terms, seems to be gaining in acceptance and popularity.


Note: (See also Monads and some examples as another way of thinking about this)


6 comments:

  1. I really like Go for some of the same reasons. Thank you for introducing me to Cobra. Looks interesting.

    ReplyDelete
  2. I only came across Cobra a couple of days ago, so I really do not know much about it, but I was interested in the line of thinking that it represents....

    ReplyDelete
  3. thanks for Cobra biting.read comparison with Python. seems interesting.trying...thanks!

    ReplyDelete
  4. You forgot the ipython notebook (with numpy) which is very very cool for scientific computing.

    ReplyDelete
  5. If you haven't already, check out the granddaddy of array languages, APL, and its even-more-functional successor J.

    Also, if implemented well, array orientation doesn't hurt performance. Using clever techniques, the compiler/interpreter can do a better job than a human programmer whose best approach is to do things in a straightforward and readable fashion, not the fashion that gives the best performance.

    ReplyDelete
  6. I'm looking at D now, which is OO + functional + imperative. It is like "C++ done the right way". There is a linear algebra library already available on GitHub ("https://github.com/kyllingstad/scid/wiki") . Using, GNU D Compiler (http://gdcproject.org/wiki/) I get the same performance as C or C++, meaning faster than Julia.

    ReplyDelete