Anatomy of a Bug (I)
How do bugs happen? Here’s an old bug of mine that illustrates how working code can suddenly break when a fix is made elsewhere.
Back when we first designed Studio 10, all new projects were tentatively assigned to the default folder
My Projects. You could later save them elsewhere, but everything always started in that default directory.
Since you can save them elsewhere, Studio keeps a list of the directories in which you keep projects. The list was optimized to save space by not including the directory
My thinking was, Studio code would always know to check the default directory anyway.
That wasn’t smart.
Later, our testers suggested that if they saved projects in a different directory, then that different directory should be the new default. They don’t care about
My Projects anymore.
That made sense. So we changed Studio to set the default project directory to be wherever the user saved projects. Much better.
But I didn’t update the list of all project directories to accomodate the change!
A heinous bug rears its ugly head.
That list, which used to “know” that
My Projects was always used, was now sometimes wrong. And this caused an off-by-one error in the size of the list. That off-by-one-error became catastrophic when when the size was 0, and off-by-one was -1.
A certain computer took a long time to count up from zero to negative one.
The bug’s since been fixed. But it took a while to discover what went wrong!