Conrad Weisert, July 17, 2011
In reviewing a couple of programming textbooks, I recently came upon the use of extended online dialogs in temporary test-driver code. The pattern was:
Now a simple dialog is an effective way to obtain input from a user. In some situations it may even be the most efficient and reliable way. But there are two things wrong with what those books are trying to teach a student to do:
It's interesting that the authors' examples overlook the easiest and most natural way of obtaining low-volume input. Every C++ or Java program invoked from the console contains a main program that looks like this:
| C++ | Java |
int main(int argcount, char* args[])
{
} |
public static
void main(String [] args)
{
}
|
Surprisingly, one book I was reviewing, despite showing the
args parameter hundreds of times, never
suggested what it might be used for. Yet the examples launched right into that
old-fashioned console dialog just to obtain a file name or some other
run parameter.
Note that command-line parameters are long established for the commands and utility
programs in mainstream
operating systems. Imagine how annoyed you'd be if you wanted to make a copy of
a file and typed: copy and then saw on
your screen: Please enter the name of the file you want to
copy.
If the tester-user is going to run your program from the command line anyway, then command-line parameters are the natural way to provide one or two pieces of input information. Conducting a dialogue is silly and annoying.
One of the same books that draws heavily upon the Please enter . . approach also advocates automating your tests. It's easy to package command-line invocations with parameters in a batch procedure or script, so that anyone can rerun the exact test cases you used at any time. It's harder to do that if the test session involved a human user at a keyboard.
Last modified 22 July 2001
Return to technical articles .
Return to IDI home page.