[getopt-sig] Separation of mechanics from semantics

Greg Ward gward@python.net
Mon, 18 Feb 2002 11:07:16 -0500


On 15 February 2002, Patrick Callahan said:
> Hmm.  Tar is botched....  Could we learn anything from an attempt to 
> "redesign" tar's user interface?  Things are the way they are sometimes for 
> reasons we can't see. Or sometimes its just botched.  Either way, I'm 
> interested enough to discuss the fine points if you're up to it?

Perhaps "tar" isn't botched so much as it is a victim of its long
history and too many cooks stirring the broth.  Like many command-line
utilities, tar has both sub-commands and options.  There are two basic
ways to implement this: the CVS/Distutils model --
  cvs [global-opts] cmd [cmd-opts] [cmd-args]
  python setup.py [global-opts] cmd [cmd-opts]
-- or the tar/(pk)zip model:
  tar -cf foo.tar ...
  (pk)zip -a foo.zip ...

I happen to prefer the CVS/Distutils model, because it draws a clear
distinction between the command and options.  When the command is just
another option, it's never clear which options have to go where, which
ones are required, and what the relations between them are.  I claim
that CVS and a Distutils setup script have a clearer, easier-to-use
command-line UI than tar and (pk)zip.

tar is also confusing because you can get away without the hyphen:
"tar cf foo.tar ..." == "tar -cf foo.tar ...".  Not only am I confused
about which options are optional, I'm now confused about which arguments
are options.  Aiieeee!!  I'm sure this is a historical artifact with no
basis in good UI design.

> The tar utility has a lot of capabilities built into a single utility
> is that the source of the complexity?  Should tar have been split into
> multiple commands?

That's one possibility, and no doubt it was rejected in the early days
of Unix because memory and disk space were at a premium.  The semantic
difference between

  cvs update
  cvs diff

and

  cvs-update
  cvs-diff

is pretty minor, although it affects the implementation considerably.
(That interface would never fly for the Distutils, of course: the whole
point was to have a *single* setup script that does everything!)

        Greg
-- 
Greg Ward - nerd                                        gward@python.net
http://starship.python.net/~gward/
God made machine language; all the rest is the work of man.