Fun Code

I’ve been going through a lot of the 3 million lines of Anarchy Online code the past months, and seen several bits that make me, as a programmer, laugh. These are completely unfunny for non-programmers, of course. And they aren’t representative for most of the AO code, because that runs pretty well these days.

Here’s a good one, from the just-in-case department:

return this?m_nValue:0;

Found the same one in the Miranda MSN plugin. Note the informative comment.

  if ( this == NULL )  // :)
    return 0;

Then there’s the gratuituos memory leak (props to André who showed me this one today):

void foo(const char * s, int v, std::map& amap) {
  char * p = strcpy(malloc(sizeof(s)+1), s);
  amap[p] = x;
}

Here’s a redundancy that I wasn’t certain about, but I checked the standard, delete NULL is allowed:

if (p) delete p;

My favourite though:

void foo(int i) {
  char b[11];
  sprintf(b, "%d", i);
 ...
}

This bombed. Signed integers require 12 chars to represent, including the trailing space. But that’s not the funny part. The funny part is that I checked who did it, and it turns out the previous person that touched the code must have found a similar error. The diff he comitted was this:

- char b[10];
+ char b[11];

How long should we wait?

WaitForSingleObject( MyThread_c::GetInstance()->m_hThread, INFINITE ); // wait max 2 seconds

Like I said, none of this is funny if you’re not a programmer. And I probably forgot some of the better ones. So, have you got any code stories of your own?

New Hitchhiker’s Guide Trailer – another one!

It’s here at UGO, and while it uses a lot of the same images from the movie that the previous one used, I like it much better. That is mostly because it has the voice of The Book in there. The Book in the new movie is spoken by Stephen Fry, but the voice in the trailer doesn’t seem to be him. Maybe that’s because I’ve heard his dubbing voice so many times?

Anyway, I need an excuse (well, another excuse) to be in London in early april. Release Date in England is April 29th, and in Norway it is… August 12th. After almost everybody else, but five days earlier than the release for the french-speaking regions of Switzerland. This is one of the very few occasions where it really sucks to live here.

[Listening to: Life On Mars? – Seu Jorge – The Life Aquatic OST]

Add 4 inches!

I finally got a new screen. Until friday, I was working on a Sony 17″ monitor, and it couldn’t do more than 85Hz in 1024×768. That is the resolution I’ve been running for almost 10 years now. I bought that screen in late ’95, when 17 inches were a lot of screen space (athough you only got 16.2 visible).

These days you can probably buy a 17″ notebook, and I’ve had 21″ CRTs at work for years. And when I got a 19″ LCD some months ago, it was just a question of time when I would have something like it at home. And here it is. Through work, I got a 20% discount on a DELL 2005FPW LCD screen, 20.1″ with a 1680×1050 widescreen resolution. I wasn’t sure if I’d like widescreen, but so far, it’s been real nice.

I turn the screen at work 90°, which lets me have two source files underneath each other, or one with very long functions. With this screen, rotating it looks a bit awkward, but I can easily have two pages of code next to each other, which is just as good. Here’s how my desktop looks. Next thing I’m going to do is hook it up to the gamecube and finish Eternal Darkness in widescreen, the way it was meant to be played.