Friday, 7 March 2014

Pair programming

I read a review in the Graun of a book about coding. I think the reviewer has taken over-seriously the talk about every child learning to code -- I think that computer programming is just one of those things, like physics or a foreign language, to which children should be exposed. Other forms of logical thinking, like the Sanskrit mentioned in that review, are probably going to have a similar effect on people's ability to think well and write well (in any language) as adults. I bet the same sort of kids would love both Sanskrit and programming, but at least the kids who hate programming can be convincingly told that there's a practical reason for learning it.

Writing programs is really excellent. I can't think of anything quite like it. I spent today "pair-programming", which is when two people work together to do a "code spike", which is when you get lots of rough code done in a short time. It's very immediately obvious when you do this that you can get further this way than by each working alone -- and I say this as someone who likes to work independently. It's exhausting on the brain but very satisfying; you can easily start a day with a problem you neither of you know how to handle, and end up the day with an unpolished but working solution.

In my previous life I don't think I ever did anything quite like this. I suppose the closest I came to it was in discussing things with intelligent colleagues, which alas is a less prominent part of academic life than people might imagine. I do know a few excellent people whom I would seek out to bounce ideas off. Sometimes at good conferences, the ones where genuine interest in the subject was unhampered by political currents and expressions of ego, you'd get excellent discussions which felt like a bit more than the sum of the previously-held opinions of the people there. So from time to time I might get the same sort of thing, a sense in a conversation between two or more people that although separately we might be quite intelligent, we are each of us more intelligent for being in conversation with the other. But the difference is that what we were talking about was not a thing we were making. It wasn't a thing where one of us could say "Well, we could just run it and see what happens", and then right-click on it and select "Run as Java program", and wait to see what the errors tell us about it. Ideas about Anglo-Saxon history or about manuscript production don't really do anything. Maybe they affect other people's ideas about things, but they take a long time to do it, and it's easy to suspect that there wouldn't be a complete correlation between the degree to which people are affected and the truth of the idea. But the recursive function we've just written either works or it doesn't; we can quickly find out that it's flawed, and use that to move us forwards.

I think that what makes writing code so compelling is that it has two complementary but different aspects. There is this baseline: it has to work. You give it to a computer, and if you've written it right the computer does what you want. But that's only the baseline: the code also needs to be well-written. Writing code that a computer can read is the (relatively) easy bit. Writing code that other humans can understand, maintain, improve, and reuse is the really difficult thing. That's where it becomes important to make your code elegant and simple. You can repeat code as much as you want for all a computer cares, it's the human beings who need it to be possible to alter a particular piece of functionality in just one place; a computer has no trouble using hideous labyrinths of interconnected methods with variables called things like "integer1", but the people who try to expand or reuse your work will curse you heartily, and probably do it badly, and it will be your fault. So making code that works is a bit like the satisfaction of making a practical physical object, and making code that is elegant is like making something beautiful. (It's a pity William Morris was born too early to join in.) Steven Poole in that review says
though some code in action can constitute art (eg certain videogames), the millions of lines of symbolic instructions themselves are not poetry
I have seen code that's beautiful in the same way as my favourite jug is beautiful (it was designed by Vera Wang). You need to know a bit about coding to see its appeal, but I think the same thing's true of football and certain complicated wines, and I take it on trust that there are things in those to appreciate. I might prefer to read that code than play the 'videogame'.

Also, when I retire I think I might learn Sanskrit. Life is good!