views:

81

answers:

2

I'm writing some unix-style Ruby scripts that take option flags. Normally, I write a lot of STDOUT.puts and STDERR.puts statments in these scripts. Now I'm wondering whether it's "good form" to put in --verbose or -q flags for switching on or off helpful output to STDERR.

Two arguments against doing that are that

  1. it would make the program more complex,
  2. users can already silence the logging output by redirecting STDERR to /dev/null

But then again, one of the tenets of the Unix Philosophy is that silence is golden, which implies that there should always be a --verbose mode flag. But doesn't this stand in tension with the tenet of making small programs that do one thing well?

And a second question would be: if silent/verbose flags are a good idea, should verbosity ever be the default?

Can some UNIX programming gurus please advise.

+2  A: 

But doesn't this stand in tension with the tenet of making small programs that do one thing well?

How would you go about extracting the error or status messages into a spearate program? They're a part of the program's doing "one thing well". A program that gives you no way to diagnose problems isn't doing whatever it does well.

Looking at Unix programs in general, the standard behaviour seems to be to output nothing or the bare minimum useful information per default, and more only when a verbose mode is activated. This makes sense, since you're usually not interested in a program's status output when it works correctly - and you shouldn't make the users of a program do extra work to make it behave as desired for the most common case.

Michael Borgwardt
I think I didn't express myself clearly here. I was proposing just normally logging error and status messages to STDERR, and just letting the user of the program redirect it to /dev/null if they wanted to.
dan
@dan: I understood you quite clearly, and like ergosys I believe that *making* the user do something to get the expected behaviour for the common case is bad style. "letting" the user redirect the output implies that he'd usually want to see the output, but that is not true.
Michael Borgwardt
Understood. Thanks.
dan
+3  A: 

Tools that I have to redirect STDERR to get them to shut up are tools I don't use. It's not that more complicated to support quiet operation.

ergosys