Web Log

Weblog

All | Cycling | Gadgets | General | Installers | Licensing and Registration | Music | Programming | Science and Nature
20051019 Wednesday October 19, 2005

Something I'm bad at

I've re-discovered something I am bad at. I'm slightly ashamed to admit it, but I am very bad at testing my own code. To be specific, I'm bad at spotting when fixing one problem causes or re-introduces a different one. I already know the fix for this. It is quite simple: write the unit tests as you go along, and make sure they all still pass after you've added a new bit. I let myself slip away from doing this, because I was feeling some deadline pressure. But I just proved to myself yet again that writing tests doesn't cost you time, it saves you time.

Well, lesson learned — properly this time, I hope.

Tag:

( Oct 19 2005, 08:12:42 PM PDT ) Permalink Comments [2]
20050920 Tuesday September 20, 2005

Stupid errors I have made, #1 of several thousand

Today's stupid programming error involves recursive directory handing in C. I was doing this, and wondering why it didn't work:

void
foo(char *path)
{
        /* stuff */
        if(condition) {
               foo(dirname(path));
               /* other stuff */
        }
        /* yet more stuff */
}

Can you see the problem? Yup, that's right, dirname() modifies the string pointed at by its argument, so when you pop up a level, your path is still trimmed. The solution is to strdup(path) before the recursive call, and free() the copy afterwards.

D'oh!

Tag:

( Sep 20 2005, 07:08:29 PM PDT ) Permalink Comments [2]

Calendar

RSS Feeds

Search

Links

Navigation

Referers