Hacker News new | ask | show | jobs
by reinhardt 5429 days ago
What about the disadvantages?

- It doubles the number of flags of the program.

- It allows invalid or ambiguous combinations: is `myloc -i -x` valid? If yes which flag takes precedence?

It seems these must outweigh the benefits or it wouldn't be so uncommon.

4 comments

Don't call it -i and -x, call it -i and --no-i or better, -i, --include and --no-include. Some getopts can provide this automatically.

Last flag wins is a common choice because it allows some script to contain yourcommand --include $@ and then you can override with --no-include.

I've seen two conventions for conflicting flags: complain and bail out, or "last one wins" so in your example, -x.
"- It doubles the number of flags of the program."

I don't agree with this. One of the advantages of command line programs is that you can have a large amount of possible arguments, but it doesn't really matter for the user, as long as there is some way to give the most common (like --help and --long-help, or listing the important options in the man page, then have a full list) . This is where GUI's fall down, you must process all options to get to ones you want; where as command line programs can have just the options you want set mentioned. (have you seen mplayer's man page lately?)

As well as having negating arguments, you also want long versions. This is so, when used in scripts, the arguments passed to a program make some kind of sense.

With your precedence argument, just look at some of the standard tools. For rm, -f will override -i. I want this behaviour, personally. It seems 'obvious' that it should be that way.

It doesn't necessarily double the number of flags, it doubles the number of boolean flags. And if you use a convention like joeyh mentioned then the length of your help text won't double, nor will the cognitive burden on users who have to remember the options.

A disadvantage of this system is that --no-x might not always make sense or read well so if you make it consistent it may be weird. On the other hand if you use --no-this and --without-that then you are increasing the documentation and cognitive burden on yourself and your users. For most geeks this is admittedly a pretty minor disadvantage but it's the only one I have off the top of my head.