Command line parsing

Russel Winder via Digitalmars-d digitalmars-d at puremagic.com
Sat May 14 07:29:04 PDT 2016


On Sat, 2016-05-14 at 16:17 +0300, Andrei Alexandrescu via Digitalmars-
d wrote:
[…]

> I showed a fellow programmer std.getopt. We were both on laptops. He 
> wanted to show me how good Python's argparse is and how D should
> copy 
> it. By the end of the chat it was obvious argparse was much more
> verbose 
> and less pleasant to use than getopt. Like you have to create an
> object 
> (?!?!) to parse the command line and many other lines of nonsense.

"verbose", "less pleasant" and "nonsense" are hardly the right terms
unless the intention is to try to convince us using advocacy research.

D will have whatever option parsing the people prepared to put in the
effort and have the permissions and rights to add to the codebase want.

Of course the more "democratic" way forward is to remove command line
parsing from the D distribution and have it in the Dub repository as a
package. Then there can be many different ways of doing things and
statistics of downloads can be used to decide which is preferred.  

This reminds me that SCons (and indeed CMake) probably need ways for
specifying dependencies and retrieving them from the Dub repository, so
that the Dub program is not needed. 

> > 
> > A table of data declaring all the things. No messing round with
> > control
> > flow during the parse. Automated message construction. Use of
> > properties and data structure for all the results.
> Where is the control flow in
> 
> bool frob, meh;
> getopt(args,
>    "frob", "This is the frob", &frob,
>    "meh", "That's the meh", &meh);
> 
> ? Honest question.

I thought we were talking the C library which advertises http://www.gnu
.org/software/libc/manual/html_node/Example-of-Getopt.html#Example-of-
Getopt as the official example and exemplar of getopt use.

> > 
> > Basically an increased level of abstraction. Imperative →
> > Declarative.
> I'm not seeing the imperative here. Care for a concrete side-by-side 
> comparison? Pick your cherries.

See above: looks like a stonking great while loop to me. However if
your use of getopt is different from that above, I can see that this
argument is taking place by two people observing two completely
different things, and is therefore not a discussion or an argument, but
a point for a reboot of the thread!

-- 
Russel.
=============================================================================
Dr Russel Winder      t: +44 20 7585 2200   voip: sip:russel.winder at ekiga.net
41 Buckmaster Road    m: +44 7770 465 077   xmpp: russel at winder.org.uk
London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20160514/f4676ed2/attachment-0001.sig>


More information about the Digitalmars-d mailing list