[getopt-sig] ANNOUNCE: Optik 1.3 released

David Goodger goodger@users.sourceforge.net
Fri, 12 Apr 2002 16:45:05 -0400


David Boddie wrote:
>> <yourscript> -f outfile --quiet
>> <yourscript> -qfoutfile
> 
> The last one is truly diabolical. ;-)
> 
> This is where having some sort of syntax style option would be useful
> because there are cirumstances in which a developer might want
> 
> <yourscript> -qfoutFile
> 
> (noting the use of "F" to avoid duplicating "f") to be equivalent to
> 
> <yourscript> -q -f -o -u -t -F -i -l -e
> 
> Is this regarded as bad style?

Yes, and wrong too.  Either the -f option takes an argument, or it doesn't.
Optik is explicit about this.  Some people want optional option arguments,
but that makes parsing (in cases like this) ambiguous and is best avoided.

Let's assume that -q doesn't take an argument. If the -f option *does* take
an argument, then '-qfoutfile' is the same as '-q -f outfile'.  If -f
*doesn't* take an argument, then '-qfoutfile' may be parsed as '-q -f -o -u
...', which may or may not work, depending if -o, -u, etc., are defined.

If optional option arguments were allowed, this case would be ambiguous.  To
resolve it you'd have to specify that the "optional option argument options"
are "greedy" (they try to take an argument first), or "non-greedy" (try to
match options first).  But what if you then want to pass an option argument
which begins with a hyphen, like a file named "-dash.txt"?  Doesn't work.

Better to leave it simple and explicit.

-- 
David Goodger    goodger@users.sourceforge.net    Open-source projects:
 - Python Docstring Processing System: http://docstring.sourceforge.net
 - reStructuredText: http://structuredtext.sourceforge.net
 - The Go Tools Project: http://gotools.sourceforge.net