Wednesday, June 27, 2007
(For programmers only)
I've had to become familiar with yet another "legacy codebase." There is no documentation, other than the code itself, and all the people who worked on developing the code are either gone or are too busy with other projects to give me an overview and tour. So I've been on my own.
In such situations, I usually start by finding the main() function and tracing the paths of execution through the code. If you're lucky, main() has a couple of lines of initialization code, a simple loop, and a few lines of cleanup code. If you're unlucky, main() is 2,000 lines long with eight levels of indentation and lots of variables with names like x, tmp, temp, and temp2.
But I couldn't find the main()! When I searched through the code directories (all 72 of them), I did find a few main() functions, but they were all in source files called test.cpp. "That must just be test code," I thought.
I was mistaken. As it turns out, every single executable's main() resides in a source file called "test.cpp."
Why? Because the first guy who wrote an executable program that linked with all these libraries made a simple test program, quite reasonably named "test.cpp." And then everyone else just copied that guy's files when they needed a new executable.
I understand why somebody might want to copy a working program to create a new program, but I had to ask why nobody bothered to rename each copy to something more descriptive. The answer: "Because then we'd have to change the copied Makefiles, and that's too much work."
Now that I get paid by the hour, I don't let such answers bother me.