Higher order programming?


So this year I entered codejam and decided to write all my answers in JavaScript. Usually I would solve any given problem in the language I felt most suitable but, I write much more JavaScript than I do anything else and the familiarity means I can write a bit faster…

It’s not going too well.

I got through the qualification round ok despite “hitting the wall” by the third of the three problems on offer. The reason I say it’s not going too well is the rubbish code I’ve created. My JavaScript looks like bad C.

My code is too crap to post here. Anybody who really wanted to could probably find it on the codejam site with some effort. I suggest nobody bother.

Anyway, hopefully by now there’s not many people around who still need convincing that JavaScript isn’t bad C or indeed, a C derivative at all… despite the semicolons and curly braces.

Still, apart from one decent object mapping section in my solution to the second problem, my solutions so far look and feel like C. Bad C. What happened to all the functional, higher order and prototypical object system code? What happened to using JavaScript the right way?

At first I told myself that the types of problems presented were really geared towards that style of coding and that it wasn’t my fault. Then I went over and had a look at some statistics from the 2008 competition.

The first thing I looked at was the competition stats for Lisp. There weren’t many people in the competition using Lisp but those that did use it were doing fine. Some really elegant solutions among the answers.

It’s interesting to go through the solutions in different languages and see how people are using those languages under the pressure of a limited amount of time for code that they know is immediately throw-away. I’ve been doing a bit of Clojure lately which may influence my opinion but the good Lisp solutions read much better that anything else I found. I know that there are a lot of exceptional C and C++ programmers out there and they were well represented in the best performers in the 2008 codejam but to me, looking at some of the code… if it was me I would probably choose not to solve the problems at all than have to write some of that code… No fun.

Personal preference? I know there’s a million C programmers out there who are much more talented programmers than I am. It’s just that, if I somehow became an awesome C programmer I’d also have an awesome migraine.

I’m a JavaScript guy and I do User Interface. If my code feels ugly and I’m not enjoying writing it that tends to infect the User Interface… and it’s the User Interface that really matters.

Anyway, for me I think it’s going to be back to SICP or The Little Schemer to see if I can rewire my brain to start solving programming problems in more elegant ways. If you’re like me, and wouldn’t want to be an exceptional C programmer even if you magically became talented enough to be one then I might suggest you do the same.

After that? Perhaps The Art of Computer Programming.

On another note, looking through some of the contestants there are a few examples of polyglot programmers who write solutions in a dozen different languages. Impressive stuff.



CoffeeScript in Action


CoffeeScript in Action book cover

I'm the author. Get it from Manning.