Tuesday, December 14, 2004

Command line: A universal programming blindspot

Every major OS today enables you to create a file whose name begins with a hyphen. Hence filenames like --help are legitimate on most systems. So is --help.class. If your class has this perfectly legal name, Java will not ever execute it. The reason is that its command-line parser (like most) is wedded to the belief that a switch character (the hyphen) will be used strictly for switches, so the parser never tests for a file name that begins with one.

I can find no parser, program or code snippet in all the code I have access to (open and closed) that checks for this possibility. Moreover, I can find no discussion of this issue. It's a true blindspot.

Of course, the problem is much greater than just Java. Most Linux and UNIX software uses the hyphen as the switch character for command-line args. Curiously, this problem does not exist in Windows, because the universal command-line character is a forward slash (/), which is not allowed in file names.

This problem points out the fact that despite the long push towards code inspection, code analysis, unit testing, etc. that has occurred during the last decade, these tools are only as good as the perceptions of the developers writing and using them. Hence, widely pervasive beliefs are still going to infect even our best efforts, until we begin to really think outside the box of our own prejudices to get at subtle aspects of software quality. I will have more on these blindspots in later posts.