2007-01-22

The Reason for Blogging

I regularly hang out at programming.reddit.com. It's a news site for programmers where visitors can vote up and down the news articles. I like it because it is geared towards programming language discussion rather than only focusing on how to use the most mainstream languages.

Mark my surprise when I found one of my own blog posts featured on the first page. It was the post from a couple of weeks back on Programming Productivity and Programming Languages. I was very flattered that people had found it interesting enough to post it on reddit in the first place and furthermore that it got enough positive votes to make it into the front page.

Of course I was eager to see the comments so I immediately open the comments page. What I found there was comments like the following:


These sorts of articles aren't very useful. Lots of vague, unsubstantiated claims, especially when claims like

All those features such as purity, closures, powerful type system, laziness and STM which makes programming in the large easier come together very nicely in Haskell.

are made.

and
I agree. It's ideological rubbish. Maybe the author should argue with guys like this

http://wagerlabs.com/2006/01/01/haskell-vs-erlang-reloaded

instead of deducing the productivity of a PL from its feature matrix.

I agree with these comments. The claims I made in my post were very much unsubstantiated and they were all ideologically motivated. Why then did I write the way I did? Clearly this kind of writing isn't very helpful for anyone reading it and so why take up any readers time with such obvious rubbish?

There is a bit of a problem with news sites such as reddit and digg and how they relate to the blogosphere. People can submit any blog post (or web site) that they see fit to these sites. It can be blog posts by anyone anywhere on the internet, written under any circumstances and in an unknown context. But when a blog post appears on these sites some people tend to read them as news articles written for general consumption. But that is in many cases not at all how they should be read. People write for many reasons and to please news hungry surfers is only one reason.

The reason I blog is not for someone to read what I've written. I started blogging to improve my writing skills. I've continued blogging because I like to write down things that come to my mind and it is a good help for structuring my thoughts. I blog for my own amusement.

But then, why do I blog, as opposed to just writing on a piece of paper? The reason for me is that the possibility that someone might read what I write helps me write. Blogging means that I have an (at least potential) audience which I can target my writing towards. This (perhaps imaginary) audience is very important for me, I wouldn't be able to write without it. I simply can't motivate myself to write only for my own sake.

So I was by no means put off by the comments my blog post received on reddit. My posts wasn't written for these people. But I am glad that there were a couple of people who actually liked the article and gave it positive votes.

I blog for my own amusement. That has and always will be the main purpose of this blog. But I've been thinking a lot lately about starting another blog where I will write about technical stuff, programming and programming languages. Why another blog? Because in my head the random ramblings that appear on this blog is very separate from my technical thoughts. The two blogs would also have very different intended audience. While this blog only has an imaginary audience the new tech blog would be directed towards programming and research peers. I think it's earnest towards both audiences to keep the blogs apart. Anyhow, if I decide to launch a new tech blog I'll be announcing it here so watch this space if you're interested.

2007-01-21

Masters Final in Snooker

I've just finished watching the final of the Masters tournament featuring the rising star Ding Junhui from China and my favorite snooker player Ronnie "The Rocket" O'Sullivan. And what a match it was.

Ding Junhui is only 19 years old but is already ranked as number 5 in the Provisional World Ranking and has already won 3 titles (being the youngest player, together with John Higgins, to have won so many titles). In the semifinal he beat Steven Hendry with a brilliant and offensive play. After that match Hendry, who seldom gives any praise to other players, applauded Ding and said that there are only two or three players in the world from whom you can't expect a second chance in a frame. He said Ding was one of them (the other two being John Higgins and Ronnie O'Sullivan. Hendry also belongs to that list but naturally he didn't count himself.) Ding seemed to be in a very good shape before the final, he even said he hoped to improve his game from the semifinal where he beat Hendry. Earlier in the week he also made a 147 frame, the highest possible score in snooker (not counting fouls) and became the youngest player ever to have achieved that on live TV. The previous record holder was Ronnie O'Sullivan.

Ronnie, as I said, is my favorite snooker player. He has his ups and downs but when he plays his best snooker there is simply no one that can match him. It's like he ceases to be a snooker player and becomes a magician, using the cue as wand to cast spells on the white ball, demanding it to go where he wants. It's absolute magic and looks so effortlessly that it must be embarrassing for the other players. On top of that he is also more or less double handed. He can play as good with his left hand as with his right hand.

Given that Ronnie O'Sullivan is so good, why doesn't he win everything? I think the problem for Ronnie is that he is himself his biggest opponent. He's having trouble with motivation and his mental stability seems to be lacking. Last month he simply walked out from a game against Steven Hendry and that is a very unusual thing to do in snooker where every player is expected to behave like a gentleman. He also seems to have a problem with longer tournaments and to keep up his concentration during a whole week or so of play.

Ronnie O'Sullivan's way to final was very good example of his mood swings. He started out very strongly beating Ali Carter with 6-1. Then he just barely beat Ken Doherty currently ranked no. 1 but wasn't showing his best game. In the semifinal he was up against Stephen Maguire and that was the worst game of snooker I have ever seen. Even I could have beaten Maguire as he played in that game. It was obvious that he was just pumped with adrenalin for this match and he didn't manage to cool down, missing just about every ball. It's a miracle that he actually won a couple of frames. O'Sullivan also played really poorly and didn't really deserve to win either.

Given the two players previous performance during the tournament I held Ding as a favorite in the final. But just barely, as I'm well aware of O'Sullivan's qualities. And it turned out to be quite a drama. Ding won the two first frames showing some superb snooker, much like in the semifinal. That seemed to wake up O'Sullivan who after that took four frames in a row including two centuries. Ding then responded, making the score 4-3. After that it was all O'Sullivan. It just seemed impossible for him to miss. Ding didn't play badly, on the contrary. But no matter what he did O'Sullivan would still find balls to play with and once he started there was no looking back.

In the tenth frame though, it seemed like Ding might have a chance to get into the match again. He had scored 65 points when he finally missed a ball, leaving only 67 points possible on the table for O'Sullivan. "The Rocket" stole the frame with 66 points against Ding's 65. I think that frame was the nail in the coffin for the Chinese.

The pressure seemed to take it's toll on Ding Junhui. During the latter half of the game it seemed like he was almost weeping, sitting in his chair and watching O'Sullivan beating him. It didn't help that the audience was very much in favor of Ronnie O'Sullivan and could be quite loud and disturbing at times. Ronnie even asked that one particularly loud spectator be thrown out of the arena, and indeed, he got so see the end of the game on a TV.

After the twelfth frame, making the score 9-3, it seemed that Ding wanted to concede the game. He went to shake O'Sullivan's hand but Ronnie wouldn't accept it. Instead he put his arm around Ding to try and comfort him and led him out of the arena. It was very warming to see such a friendly gesture from O'Sullivan when his younger opponent was so obviously upset. Later Ding Junhui said that he thought that the game was over, being best of 17 frames. That might be true but I'm somewhat skeptical to that explanation. It seemed that Ding was almost crying and he had essentially given up the frame before with a very poor, and not even half-hearted defensive shot. So having Ronnie O'Sullivan as an opponent turned out to be a mixed blessing. On the one hand Ding got a very tough lesson in snooker and in how bad the pressure can be in a final. On the other hand O'Sullivan turned out to be a very supportive friend who wanted to help him when he was almost caving in for the pressure. After the match, O'Sullivan made sure Ding Junhui didn't have to give an interview, which is otherwise customary. He could leave right after he received his second prize.

So it was a very good match to watch. Both a bit of drama and some of the best snooker I've ever seen, especially from Ronnie O'Sullivan. I hope he can pull himself together for some more stunning snooker later this spring. As for Ding I'm sure he will win many more titles and become one of the great names in snooker.

PS. For the record, the final ended 10-3 for O'Sullivan.

2007-01-19

The Last Functional Programmer

One of the things our computer science department is famous for is its history in functional programming. People who have been working here include John Hughes, Lennart Augustsson, Thomas Johnsson, Niklas Röjemo, Jan Sparud, Urban Boquist, Magnus Carlsson, Thomas Hallgren, Koen Claessen and some people like Philip Wadler, Amr Sabry and Andrew Gordon have made longer visits here. All these people have made important contributions to the field of functional programming and Haskell in particular.

Given this dire history it was not without pride that I yesterday was given the title "The Last Functional Programmer" of the department.

The history behind this title is that a lot of the people do not work at our department any longer. The only two people left are John Hughes and Koen Claessen. John has switched over to Erlang and Koen mostly does hardware verification these days. So, when one guy from the proglog group needed a subreviewer for a paper relating to functional programming he was directed to me, being the last functional programming outpost at our department.

Although I was proud to be given this title it's also sad. Functional programming is really fun and I wish there were more people doing it at our department. There are people here who use functional programming and we can exchange some ideas but there's really no exciting research going on. I guess I'll have to move to a better place when I've finished my PhD. Or maybe I need to love some other field.

2007-01-10

Yak Shaving

Yesterday I stumbled upon one of the coolest and useful expressions I've heard in a while: Yak Shaving. What does it mean? Here's a quote from the link:
"I was working on my thesis and realized I needed a reference. I'd seen a post on comp.arch recently that cited a paper, so I fired up gnus. While I was searching the for the post, I came across another post whose MIME encoding screwed up my ancient version of gnus, so I stopped and downloaded the latest version of gnus.

"Unfortunately, the new version of gnus didn't work with emacs 18, so I downloaded and built emacs 20. Of course, then I had to install updated versions of a half-dozen other packages to keep other users from hurting me. When I finally tried to use the new gnus, it kept crapping out on my old configuration. And that's why I'm deep in the gnus info pages and my .emacs file -- and yet it's all part of working on my thesis."

And that, my friends, is yak shaving.

I recognize this situation so well. Sometimes I feel like I don't do anything but Yak Shaving. That can be really frustrating and drain your energy pretty fast. Which means it has to stop.

Now at least I have a name for it so I can say to myself: "I'm Yak Shaving. Stop doing that and go do some important stuff instead".

2007-01-09

Programming Productivity and Programming Languages

Recently I've read two blog posts about programming productivity and how it can be improved by better programming languages. I'd like to expand a bit on them.

The first post focuses on code reuse. The thesis is that the central thing that increases programming productivity is code reuse. As soon as you can reuse some bits of code you save effort. How does this relate to programming languages? One way is that programming languages can supply code in the runtime system, such as garbage collection. Thus, the programmer gets a well tuned bit of code which is most certainly correct and which he doesn't need to think about to use. Another example mentioned in the article is objects. It is indeed possible to program with objects in C but this programming pattern is captured by a language construct in object oriented languages and we can therefore reuse it.

The latter half of the post makes a case for standards. Having to choose from several libraries that does the same thing or programming constructs that can achieve the same thing are bound to make a mess. According to Murphy's Law, when you want to use libraries A and B, library A will use feature 1 and library B will use feature 2 and that will render them incompatible. So standards are good, be it libraries or programming idioms. They help making programs more composable.

Which leads me to the second post which talks about Composability and Productivity. This post starts out repeating a lot of the previous post but focuses on composability. But it goes further down the composability track talking about the problem with state. When composing two stateful pieces of software it might be important when the state changes happens and sometimes that leads to composability problems.

But there are even more interesting issues in composability and reuse that neither article mentions. One is concurrent programs. These are extremely hard to compose if they use ordinary locks and sometimes it is out right impossible to compose them. One promising line of work here is software transactional memory which can bring composability to concurrent programs. If think this sounds interesting you should check out the papers by Simon Peyton Jones on software transactional memory (or STM for short). STM has transactions, bits of code which either are run to completion or aren't run at all (perhaps due to a state change which happened while the transaction was running and which invalidates it's view of the world). The salient feature of STM is that it enables the programmer to compose transaction. Hence it increases composability.

The interesting thing is that this STM fits particularly nicely with Haskell. Why is that interesting? Because Haskell has some other very special features which makes Haskell programs more reusable and easier to compose.

One of the obvious benefits of Haskell when it comes to reuse is its strong type system. Writing reusable code is a lot easier if you don't have a very narrow minded type system which gets in your way all the time. To avoid that you can either ditch the static type system and go with dynamic types, which is what Lisp, Scheme, Ruby and Python does. The other option is to use a more fancy type system which lets give types even to the most abstract pieces of software. That way they can more easily be reused. This also improves composability.

One last feature of Haskell that I want to mention is laziness. Anyone who has ever heard of Haskell knows that this is the one feature which sets it apart from other languages (modulo Clean). Laziness makes evaluation order difficult to predict and therefore it is a bad idea to have state in a lazy language. Therefore Haskell is pure, allowing no mutable variables or IO except in a confined imperative sublanguage. As the first post I linked to above have already pointed out state is bad for composability. That should make Haskell programs more composable and reusable. While I think this is true it's not why I mention laziness. Lazy evaluation, used correctly, can enable a new kind of modularity which takes great effort to achieve by other means.

The standard example of modularity from laziness comes from John Hughes' classic article "Why functional programming matters" but I don't think it has gotten enough attention so I will repeat it here. Suppose you are writing an AI for some board game such as tick tack toe or chess. Writing good ones can be really tricky if the board game if moderately complex. In Haskell you would start out by generating a tree which models all possible moves from the current positions on the board. This tree can infinite. One can then write small functions which operates on this tree, such as pruning it or reorder branches to make things faster. Lastly one can compose these functions to construct the final evaluation function. The crucial thing here is that the small functions operating on the tree are highly reusable. It is very easy to cherry pick them and reorder them as you see fit. Therefore it is very easy to try out several different algorithms with very little effort. All this spells: Programmer Productivity. Lazy evaluation is crucial here in making sure that only parts of the tree that are actually needed are computed.

For those of you who think that this sounds horribly inefficient I have two answers. First, if you find a really good search algorithm this way then the constant factors due to lazy evaluation and many function calls doesn't really matter. Secondly, there are techniques to automatically remove the game tree which can make the program almost as fast as a hand tuned one.

One good example of where they've explored the modularity of laziness is the paper "Modular Lazy Search for Constraint Satisfaction Problems". It's one of my favorite papers and it's well worth a read. I have more to say about this paper but I'll save it for another post.

OK, so this post turned out to be a sales pitch for Haskell in the end. No one who knows me would be really surprised by that. But I really do think that Haskell has a lot of features that takes code reuse and program composition to a new level. All those features such as purity, closures, powerful type system, laziness and STM which makes programming in the large easier come together very nicely in Haskell. So it's no surprise that the latest revisions of C#, Java and VB all borrow heavily from Haskell and it's language kins.

I completely agree with the posts I linked to above: Reuse and composability are very good for programming productivity. And there's a whole lot of things that can and should be done at the language level to improve these issues.

2007-01-04

IMDB Top 250

I'm a huge fan of IMDB. I use it all the time to look up facts about various movies and actors that I've seen or am going to see. The site is just packed with information which makes it a gold mine for any film lover.

One page that I particularly like and visit every now and then is the Top 250 list. The site allows any visitor to vote on the movies and based on these votes this list shows the 250 most popular ones. It's a very good list if you're looking for a good film to watch.

Every now and then I check the Top 250 list to see which movies from the list I have seen and which I should consider seeing. And today I was happy to cross off one more movie on the list: Casablanca, current ranked as number 6 on the list.

Seeing a classic such as Casablanca can be difficult. When a movie have such a high rating it's hard not to have very high expectations. And in my experience older movies often have a much slower tempo which can make them difficult or even unbearable to see unless you're in the right mood. Because of these problems I often postpone watching classics indefinitely. I'm constantly waiting for the right moment to present itself, to get into the right mood for watching the movie. But somehow that moment never seem to come. We taped Casablanca many years ago but have never watched it.

It's better to do what we (me and my fiancee) did today, watch the movie when it runs on TV. Don't record it, don't rent it, just take the time to watch it when it actually runs.

It's not difficult to see why Casablanca has become such a classic. Despite being recorded in 1942 the movie feels very modern. The dialog is absolutely fantastic and the movie is fast paced, not boring for a single moment. It is also filled with quotes that have gotten a life of their own: "Play it again, Sam", "We'll always have Paris", "Of all the gin joints, in all the towns, in all the world, she had to walk into mine." etc. (More quotes here.) All I can say is, if you haven't seen it yet I can heartily recommend it. It's worth every bit of it's status as a classic.

Despite being a big fan of movies I am a little embarrassed to admit that I haven't seen the top three movies on the list: "The Godfather", "The Shawshank Redemption" and "The Godfather: Part II". Watching the Godfather trilogy is one of those projects that I suspect will never happen. The pressure of finding the exact right moment and mood to watch these movies is so big that I'm afraid it will never happen. As for "The Shawshank Redemption", I've bought the DVD so I hope it will lower the threshold for me to get around and watch it.

To make it a little easier to see what movies I have seen on the Top 250 list and what I thought of them I wrote a little greasemonkey script which adds an extra column to the list. This column shows for each movie what vote I have given to it. I've made the the script publicly available in case you would like to try it out yourself. Of course if you install the script it will show your votes, not mine.