Archive for the 'Principle of Least Surprise' Category

Ruby DL

I’ve been meaning to learn Ruby for a while, and I finally found a suitable project. So far my experience has been fairly good. I ran into one particularly annoying problem with the DL library, which is an otherwise cool way to make calls into dynamic libraries. Before you can do this, you’ve got to tell Ruby what the function prototype looks like. That’s where I ran into this gem:

extern "int foo( char * )" # doesn't work
extern "int foo(char *)" # works

The error message is absolutely worthless, so you essentially have to discover this by trial and error.

Principle of Least Surprise

If you violate the “principle of least surprise” you should be prepared to face the wrath of your users. Here’s today’s example:

The Windows start command does about a million things. One of them is to launch a new process. If you are benchmarking, it can be useful to launch the benchmarked process this way so that you can influence it’s scheduling priority, processor affinity, etc.

The command supports the following two switches, among others:

  • /B – Start application without creating a new window.
  • /WAIT – Start application and wait for it to terminate.

The usage summary includes this output:

["title"][/D path][/I][/MIN][/MAX][/SEPARATE|/SHARED]

Notice the order of the /WAIT and /B switches. Guess what? If you issue the switches in this order, the /B switch silently cancels the effect of the /WAIT switch. You need to use the switches in the other order if you want them to work properly. As far as I can tell, these are the only two order-dependent options to start.

Believe it or not, this is the intended and completely undocumented behavior.

Funny, but knowing that this was done on purpose in no way gives me the last hour of my life back.