top | item 39734046

(no title)

LegibleCrimson | 1 year ago

I hate that behavior of GNU sed (and also of mktemp). Having a flag optionally take an argument is just so weird and surprising, and the syntax is always unexpected and inconsistent.

discuss

order

jppittma|1 year ago

I don't see it as a flag that optionally takes an argument, but rather a flag that makes an optional argument mandatory.

LegibleCrimson|1 year ago

No, that's how optional flags should work. I mean how specifically -i works. With GNU sed:

-lN, --line-length=N, -l N, --line-length N

All work the same, set line length to N.

-iSUFFIX --in-place=SUFFIX, -i NEXTARG --in-place NEXTARG

Don't all work the same. The argument is only actually taken if it's attached to the flag directly. In the latter two forms, no backup is made.

GNU mktemp is similarly annoying, but different, with the --tmpdir flag.

-pDIR, --tmpdir=DIR, -p DIR, --tmpdir NEXTARG

Only the last one is different. If you use --tmpdir literally without attaching an argument to it, it defaults to $TMPDIR, otherwise it takes in DIR.

This is inconsistent and unpredictable. A flag should either take an argument or not.

I also dislike Python's argparse variable-length nargs behavior for similar reasons. Even with an integer nargs, it makes for an ugly command line, but with variable-length ones it just gets hideous, and can make it impossible to pass an argument beginning with a hyphen to a flag.