Friday, July 08, 2005

Fixing things

HiQLab now compiles and runs on the PowerBook. The problem, as it turns out, had to do with a compiler issue in the Xcode version of gcc-4. Somehow the default destructor was getting bungled for classes that contained STL vectors. In a way, I'm glad that this happened, because it meant that I was forced to do something I'd intended to do for a while anyhow (default destructors have this creepy way of screwing up builds if you aren't careful). It also meant that I had the chance to check out some of the Xcode debugging tools.

It might be more accurate to write that I'm not glad that I had to make the changes now, but I'm glad that it took me so little time to figure out what changes to make. Besides the destructor problem, which is less a bug in my code than it is a compiler problem, I also found a place where I'd managed to deallocate two things out of order. I need to add a test case to my automated system so that I can check for that more carefully in the future.

I always have mixed feelings when I can find a bug quickly. On the one hand, computers are notoriously more exacting and literal-minded than people are. Consequently, I doubt I'll ever reach the state where I write bug-free code the first time through, except when writing the simplest programs. Given that I will make stupid mistakes, I rejoice in the fact that I can learn enough to recognize and rapidly compensate for certain classes of errors. But given that the whole name of the game is to offload as much mechanical work as possible onto the computer, I wonder if I could improve my tools so that such bugs don't plague me in the first place.

Yes, I know that by programming in a different language, I can get rid of an awful lot of resource management errors -- and that's part of why my front-end is in Lua, which is a garbage-collected language. As for the other stuff, I refuse to write matrix code in Java, and I refuse to rewrite large volumes of Fortran, so the Frankensteinian mixture of C++, Fortran, Lua, and MATLAB that I use for HiQLab still seems like a good engineering solution. Perhaps one day I'll change my mind and add in a few more languages.

On an unrelated note, I've also decided that my experiment with jsMath, while exciting, ultimately didn't work out as I'd planned. If you're interested in that handful of articles, you can read the equations in TeX form -- which is not such a terrible thing. The remainder of my planned five-part series will probably be written as PDF files.