[getopt-sig] Looping versus object-oriented framework
A.T. Hofkamp
a.t.hofkamp@tue.nl
Wed, 20 Feb 2002 10:45:46 +0100 (CET)
Hello all,
A discussion that seems to have died out, but which I still consider relevant
is the looping versus object-oriented approach of option processing.
I feel there is a definite need for something extremely light-weight, like a
simple loop, as proposed by Russ Cox on 12 feb, like.
for opt in sys.argv[1:]:
if opt == '-d':
debug=1
As people correctly pointed out, this approach is broken due to complexities as
'-dc', which is either '-d -c' or '-d c' (with c the argument of the -d).
The step that we THUS need an object-oriented framework is a bit too big for
me. For simple scripts, as well as for people that do not grasp the
object-oriented concepts, the above is very appealing if it 'does the right
thing'. At least, the number of programs with broken option processing may
decrease, which is already a step forward.
On the other hand, for non-trivial option processing (or for people that very
much like the object-oriented techniques, like most of us), there is also a
need for more compact notation and/or more power of an object-oriented framework.
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 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).
Maintaining the loop approach is thus equivalent to maintaining the inner
parsing loop for us.
Releasing the looping interface to external users is then trivial.
Albert
--
Constructing a computer program is like writing a painting