Shooting Your Foot through the Windows

When I was studying programming, some million years ago, I encountered a nice explanation about the difference between programming languages. It used a simply uniform “challenge” for each language: “How would you shoot yourself in the foot?” The different implementations were used to explain the special characteristics of each shooting your leglanguage. It stated with “C” where you simply point your gun at your foot and shoot (and nobody will understand what you did). In some more structured languages you will need to construct much more complicated structures to accomplish (or fail to accomplish) the same daily programming task… for good or bad.

Writing software (SW) is sometimes a boring routine work, but new bugs come in all shapes and colors and they always succeed to thrill and astonish me. And the real joy is when you find at last that it was not your bug after all. So here is a nice story from my work.

I had to analyze data from some experiments. To save the results in an orderly way, my SW builds a special directory for each experiment, using the experiment’s ID as part of the directory’s name.

When I first came to install the SW on a customer’s computer, it looked as if everything was running just fine. But when we tried to look at the results there were not one but two directories with the same name and both seemed to be empty. We tried to delete the directories. One was easily deleted but Windows Explorer failed to delete the other. Now I tried to look at the contents of the undeletable directory, but couldn’t view its content (even though initially it seemed to be empty).

I wanted to repeat the experiment, so I tried to rename the undeleted directory and failed. I tried to rename its father directory and Window Explorer refused to do this either. Finally I succeeded to rename the grandfather directory. I repeated the experiment and had another pair of same-name apparently empty directories, one deletable and one stubbornly persistent.

I went back to my development station to scratch my head. I googled “two directories with the same name in Windows”. There were more dummies like me asking “how come I have two directories with the same name” and the only answer I’ve seen there was “no, you don’t”.

I investigated it farther, adding prints at my directory-creating function, and found the answer. The experiment’s data contained the ID string with a blank as the last character. Somehow my SW created two directories, one with the blank on the end of the name and one without it. My customer and I, looking at the two directories’ names, were right to judge that we see exactly the same name.

But apparently it was Windows Explorer that was shooting itself (and me) in the foot most effectively. The data was actually (and correctly) saved in the directory with the blank in its name, but when I selected this directory for display in the Explorer it showed the content of the other empty directory. When the empty directory was removed the blanky directory refused to show its contents, or to be deleted or renamed.

To be fair and technically helpful, it was an old Windows Vista operation system on the customer’s computer. If you succeed to repeat such a bug on any other system please let me know.

* * *

Feedback about UNIX

I have a good friend from the UNIX world. He would regularly reproach me for sticking with MS Windows…

But when he called today he said the problem of file names that end with blanks is well known in UNIX. It is common practice to create files by scripts, so there are more opportunities to add blanks to names by mistake. And, there also, common graphical file-handling tools fail to handle these files. He even mentioned that intentionally creating such files is a known “practical joke” in the community.

Advertisements