November 2006


Even though it says “’til morning is night”, my teacher says it means “’til morning”.

Shana

img_5207-1.JPGIt’s -22 but it’s beautiful here! 😀 We’ve had snow falling for two or three days so everything is white, and looking out our bedroom window across the city it’s all twinkling lights through the haze of snow. This morning the kids and I went sledding on a nearby hill and had a blast. Before heading home we sat on some rocks and pulled out a thermos of hot chocolate, and drinking it with the snow falling on my face brought me back to cross-country skiing in Sept-Iles. The kids were cold but having so much fun they didn’t once complain until just as I was pulling them up to the garage back at home (of course at that point mayhem broke loose!). Perfect timing!

Here’s a stumper.  The programme I’m writing crashes and it’s my job to fix it.  There’s one good thing about this crash:  it’s easy to reproduce–four simple steps and it crashes every time.  The really tough bugs are those that only crash when the moon is full and the tide is going out.  But there’s nothing else easy about this bug.

First off I’ve already spend two full days on it.  Two days of slow and painful debugging earlier this week, and I thought I’d found the problem.  I gleefully told everyone I had the bug licked, but another programmer in the office showed me a case where it still crashed.

Secondly it only happens with a “release build”.  That needs explanation for non-programmers.  When I’m programming I can build my code as a “debug build” or a “release build”.  The debug build is really quick to build and has lots of extra goodies in it that make it easy for me to see exactly what’s happening under the hood while it runs.  But it runs really slowly so we’d never give it to your users.  The release build is optimized–makes for much smaller and faster .exes.  In theory a release build and a debug build do exactly the same thing, so if one works the other should to.  But once in a while you get bugs like this one, where it works in debug but not in release. 

That means I can’t use all my fancy debugging tools to examine the state of memory and see what lines of code are being run.  That’s a big handicap.  But not the end of the world.  I can still hook up my debugger to a release build and get some information about what’s happening.

But this crash only happens when the debugger is not running.  Ouch!  If I run the release build through the debugger, it all runs fine.  If I don’t use the debugger, it crashes.  I feel blind without my debugger.  This is really getting harry.  I remind myself that life is an adventure.

This doesn’t always work, but on the off-chance that it will I try running the application with no debugger, doing three of the four steps, then attaching the debugger before doing the fourth.  To my relief, it still crashes, only this time I’m in the debugger so I can see the exact line of code it’s crashing on, and look at the state of memory to hopefully understand why.  Surprisingly it’s in a completely different part of the code than I expected.  And I realise soon enough why–the memory is all messed up, the bug must have happened elsewhere and that sent the code off on a wrong tangent. 

The debugger won’t be much help after all, I’m still no closer to understanding where the crash is happening, let alone why.

I quickly confirm my theory that this isn’t where the real problem is, because a very minor and innocuous change to the code moves the crash somewhere else.  At least this “somewhere else” is closer to where I’d have expected something to go wrong, so for the moment I’ll assume I’ve found the area, and concentrate on finding the exact line of code.

I don’t have 20 years of programming experience for nothing!  In the good ol’ days we didn’t have debuggers.  I dust off my memories and try some old-school techniques. 

yo1.gifTo figure out where in the code the crash is happening, I sprinkle “MessageBox”es liberally throughout the area I suspect.  A MessageBox is just a little dialog box that pops up with a message of my choice and an OK button.  Most of the time I just number them, so the message is “yo 1” and “yo 2” and so on.  That way I can run the application and at the same time look at the code and see where it is in the code.  When I do that fourth step that causes the crash, I get the “yo 1” message, hit OK, get the “yo 2” message, hit OK, and so on.  After “yo 4” it crashes without showing “yo 5”, so now I know the exact line of code.  The code itself still looks fine though, so now I need to figure out why.

And I still have this nagging suspicion that any minute something will show me I’m still in the wrong spot in code, and the only reason it’s crashing here is because something else completely unrelated got corrupted.

debugger.jpgI work with three 21″ monitors, and one of them is normally packed with debug information, showing me in real-time memory, breakpoints, trace messages, variables, registry values, all kinds of useful stuff.  I have none of that now, but I can get at it the poor man’s way with a MessageBox. yo2.gif So instead of the “yo 1” message, I add a few more boxes displaying values of certain key variables.  I can see that the line of code it’s dying on wasn’t supposed to be run at all, so I look at the values of variables that were supposed to cause that line to be skipped.

And that’s when I find it.  Eureka!  To my chagrin it’s my own bug.  Worse yet I fixed a similar bug elsewhere just last week.  And this one’s been staring me in the face all day while I painstakingly added MessageBoxes all around it.  But the relief of having found it and being able to move on is stronger than the depression at having caused it.  Isn’t it great when you can make a mistake and still feel good about fixing it?

One more day and one more bug behind me.  That is the sometimes-life of a programmer.

Some inspiring news I found amidst all the strife going on in the world today:

Illness unmasks generous ‘Secret Santa’

I just read this on MSNBC:

An Iraqi official, who spoke to The Associated but declined to be named for personal reasons, refused to say how many vehicles were in the convoy, who hijacked it and how the freed captives were released, explaining that he didn’t want to jeopardize the work of U.S. and British forces.

A U.S. Embassy official, who refused to be identified because he was not authorized to release the information, told The Associated Press that the convoy included 43 heavy trucks and six security vehicles. Some of the hijackers were dressed as Iraqi police and those men took away 20 vehicles, he said.

Go Iraqi official!!  It makes me so mad to read things like the second paragraph, where someone discloses information but refuses to be identified because they know they’re not supposed to be talking.  First off they shouldn’t talk!  Secondly the paper shouldn’t publish what they say.  Third the reporter should be legally forced to disclose his source and the source should be fired, fined, and jailed.  He’s putting people’s lives at risk.

Anyway, I was very happy to see the Iraqis have more sense and civility than American embassy officials, though it is kind of funny that the reporter used up a whole paragraph to say that someone didn’t say anything.

Now we’re talking!!

Canada Post is joining a handful of other countries in introducing “Permanent Stamp“.  They have no monetary amount listed on them, just a “P” for “Permanent”.  Buy them today at 51 cents, and when the price increases to 52 cents in January, you can still use them (for domestic lettermail only).  (Actually they say they’ll also accept today’s 51 cent stamps even after the price increase.)  It’ll save them money because they won’t have to print so many 1-cent stamps.

I did a test the last couple of weeks, and those tree-huggers don’t know what they’re talking about

One week I drove as I normally do: not overly aggressive but generally feeling like I have to rush and certainly not trying to save on gas.  I measured my gas mileage after one week of that normal driving:  24 mpg (in our new Suzuki Aerio, though strangely that’s the same mileage we get in our much older and roomier and heavier and more powerful Nissan Altima).  It was a typical week for me.  The vast majority of the driving was around a 15 km commute to the Bow River in the morning with my bike on the roof rack, and back in the evening, with a few errands on the weekend and the occasional evening.

The next week I used all the tips I could to lower my gas mileage:

  • Drive the speed limit.
  • Coast to stops long before the red light or congestion.
  • Accelerate slowly.
  • Watch traffic ahead to drive at a steady pace.
  • Use larger roads with few stop lights or stop signs.

The result:  24 mpg.

No change whatsoever.  I’m back to my usual driving habits.