Monday 19 November 2007

Hip friend

Spot the famous theoretical computer scientist singing with Bloc Party earlier this year?!

Laziness in C#/LINQ

Perhaps this post should be called "The influence of Haskell".

One thing that people often don't realize is that when people (e.g. my buddy Erik Meijer) say that IEnumerable is a lazy list, they *really* mean it! Consider the following code in C# 3.0. It queries a database (in this case an array) by filtering out those elements that are not less than thirty. It then takes this resulting array and filters out those elements that are not more than twenty. The result is then printed out.


var MyDatabase = new int[] { 1, 25, 40, 5, 23 };

var query3 =
from x in MyDatabase
where LessThanThirty(x)
select x;

var query4 =
from x in query3
where MoreThanTwenty(x)
select x;

foreach (var r in query4) Console.WriteLine(r);

In fact, this is NOT the semantics. It's lazy lists a la Haskell, not strict lists a la ML. To see the difference, let me give you the code for pne of the filter tests (I'll make it side-effecting so you can see when it happens...)

static bool LessThanThirty(int x)
{
Console.WriteLine(x+"? Less than 30");
return x < 30;
}


Now try running the code. Not what you expected? That's because this is lazy programming!!

If you're a Haskell programmer, this is natural; although I suspect that programmers from more conventional languages might find it a little tricky.

POSTSCRIPT: Okay, a number of people have asked me to give the result of running the code. It's as follows (where I've added some formatting to help you see what's going on).

1? Less than 30
1? More Than 20

25? Less than 30
25? More Than 20
25 //OUTPUT

40? Less than 30

5? Less than 30
5? More Than 20

23? Less than 30
23? More Than 20
23 //OUTPUT

So you can see the laziness working here, in that we get alternating Less-than-30, more-than-20 calls. Cool!

Slovenka Leta 2007

Mateja is one of the fourteen nominees for Slovene Woman of the Year 2007. Unfortunately not much is online though... (There was also a 2 page spread in Delo - the national broadsheet - unfortunately, you need to subscribe to read the rest of the article:-()

I'm really very proud! We're looking forward to the awards ceremony in January (hopefully it doesn't clash with POPL!)

Monday 5 November 2007

Live maps vs Google maps

I'm currently visiting the mothership in Seattle. Yesterday I had a spare day (I came early to help with jetlag - given that I'm blogging at 05:38 it clearly didn't work!). To help this poor UK driver with the routes between Kirkland and Seattle I went to Google Maps. Just out of interest I went to Live maps, which I haven't used in a little while.

I realize that I'm (a) employed by Microsoft, (b) basing my conclusions on a single experiment, and worse (c) going against the rule of Coolness, but here's the reality: LIVE MAPS IS SIMPLY MUCH BETTER THAN GOOGLE MAPS! The maps are clearer, the photos are a million times better and the new UI is awesome! Microsoft is ahead on this game (and how often can you say that?!)

If only MS stock was as good as Google's...

Friday 2 November 2007

OOPSLA: Time off

I'm now back from OOPSLA and just about recovered. It was a really interesting conference. As always it was the people not the talks that were the highlight. (There were good talks though!) I'm still particularly excited by Second Life Scripting (thanks for the tutorial William and Cristina!). I was also impressed by my friend Erik Meijer's preaching to the masses about the joys of Haskell.

After OOPSLA was over I had some time before my flight back to the UK. I went to the Musee d'Art Contemporain. It has a smallish collection of Canadian modern art and currently three expositions by Karel Funk, Thomas Hirschhorn and Vik Muniz.

For me the highlight was the Brazilian artist Vik Muniz. He makes "temporary art" pieces using real-life objects and photographs them. (The "original" piece is typically destroyed leaving only the photograph.) There's a lot to admire in Muniz's work - both the clever dialogue about the meaning of art and also his incredible skill in creating the work. He has used chocolate sauce, tomato ketchup (a wonderful pair of Warhol-esque Marilyns), dust, toy soldiers and many more strange items. There was also an interesting documentary about the artist which I found really helped me appreciate his work. I hope he comes to the UK sometime soon. He has a website.