Friday, September 27, 2013

2001, 1968 and 2013 - reheating a blog post

I went to see 2001: A Space Odyssey one Saturday afternoon a few months ago, and drafted some notes: just found them again, so here goes …

First, all those childhood memories from when I first saw it. Was it really 1968, or a bit later? Whatever the case, I was a teenager coming to the end of a sci-fi infatuation. Despite moving on, we took for granted that by 2001 there would be moon bases, expeditions to Mars, and that space would be normalised.

Clarke and Kubrick tried so hard to make it as accurate as possible, and the wonderful HAL's legacy has a whole lot of stories about that. The most remarkable is of the two of them visiting Bell Labs and seeing hearing state-of-the-art speech synthesis: a computer sings "Daisy, Daisy" – just what HAL sings as he's being deconstructed by Dave. It's hard not to be moved by that.

The late 60s and 70s were a golden age for American film: 2001, Nashville, One Flew Over the Cuckoo's Nest, the Deer Hunter, and it's impossible to imagine that something like 2001 could be made now. Why?

First the speed of the thing: it's slow – with little dialogue – but the sound is so carefully done. Heavy breathing when Dave is in the spacesuit, some isolated conversations … and the music is only played on its own: you hear the music, and see how it works with the visuals: it's emphatically not used simply to pump up the adrenaline.

Then the visuals: remember then no one had even seen the earth from the moon (“earth rise”) when the film was made: it is mattes and models, but even though it's not photorealistic, it works. Way before CGI, but just as good!

HAL, as Stork suggests, is the real star of the film … one big brain, of course, and no PCs, but less anachronistic now (“internet of things”) than it was in 2001 itself.

And the actors? No famous lead players, but good old British character actors: Leonard Rossiter – Reggie Perrin – and Margaret Tyzack – Forsyte Saga – who also appears in A Clockwork Orange.

Of course, some things are “wrong”: there are no PCs, for instance, but the most noticeable is the prominent PAN AM logo on the space shuttle: Kubrick and Clarke were good on the science, but less on the economics …

From imperative to functional in Java 8: paper review

I have been writing functional programs for thirty years, first in KRC, then in Miranda, and more recently in Haskell and Erlang. In the past few years, though, something rather remarkable has been happening: the essentials of functional programming have been popping up in more “serious” mainstream languages: JavaScript, C#, C++ and now, with the advent of the 8th version of the standard, Java. What is this functional core that’s coming into these languages: the ability to compute functions as a part of the work of a program, and to pass these around as parameters or return values of other functions: closures as “first-class citizens” in Strachey’s words.

But why is this happening? As the authors of this fine paper explain, it is to exploit the parallelism that is now a feature of some many computing platforms, from smartphones and tablets, through laptops and desktops to servers and supercomputers. To give one example: mapping a function across a collection data structure is one of the key parallel patterns, providing the data analogue of a linear (control) pipeline.

Given the opportunity, how can we program using these new features? One possibility is to start from scratch with these new constructs, but a more attractive option is to refactor existing code to exploit these features: that is precisely the topic of this paper. The authors show how refactoring opportunities are identified, and what transformations need to be performed. Moreover, they anatomise some of the attendant difficulties: how are side-effects to be handled? how to deal with different scoping regimes between anonymous inner classes and closures? Their work is validated through a set of substantial case studies, and made available through the standard Net Beans distribution.

I would recommend this paper to anyone interested in exploiting the parallelism inherent in many standard programs, as well as anyone who would like to see a justification for machine-supported refactoring. Finally it is a remarkable vindication of getting students involved in research: two of the four authors took part as undergraduate summer interns.

This is a draft review for Computing Reviews of Crossing the Gap from Imperative to Functional Programming through Refactoring.