[getopt-sig] Looping versus object-oriented framework

Greg Ward gward@python.net
Wed, 20 Feb 2002 21:49:44 -0500


On 20 February 2002, A.T. Hofkamp said:
> A discussion that seems to have died out, but which I still consider relevant
> is the looping versus object-oriented approach of option processing.

Definitely.  I prefer the OO style for most things, but if I had to
implement a tar/rpm/(pk)zip style interface, I think I'd prefer
something like Russ' iterator interface.  It just seems better suited to
cases where an earlier option affects the meaning and validity of later
options.  (I generally think this is bad UI design, which is why I
haven't felt the need for an iterator interface.)

[...digression on pros and cons of iterator interface...]

> In short, I think there is a need for both.  Providing both gives
> power to those who need it and simplicity for those that do not want
> power, with the option of 'upgrading' to the latter group as their
> requirements increase.

I have been thinking along those lines.  My plan is to see if I can
extract the bits of Optik's OptionParser class that grok "-" and "--"
from the bits that say "-a is valid, --flobnix is not" and bolt an
iterator interface on.  It will probably look a lot like Russ' code,
which I finally sat down and read tonight.  Then we could have one
module that provides both "OptionParser" (much like Optik's current
class) and "OptionIterator" (a stripped down option parser that lets the
application make all the tough decisions).

(I've delayed doing this because there are some other cleanups/tweaks I
want to make in Optik's code, and this is going to involve some fairly
heavy lifting.  Even though it wil be experimental and on a CVS branch,
I would like to make my life easier if it ever gets folded into the
trunk.)

> I also think both approaches are not contradictionary with each other.
> For the user they may seem contradictionary, but for us, programmers of the
> option parsing module, the former is at the core of the object-oriented frame
> work (someweher deep in the parser, we need to loop over the command-line,
> exactly like the looping approach does).

Absolutely!  It might still be possible to be all things to all
people... ;-)

        Greg
-- 
Greg Ward - Unix nerd                                   gward@python.net
http://starship.python.net/~gward/
NOBODY expects the Spanish Inquisition!