Am I reading this wrong, or is std.getopt *really* this stupid?

H. S. Teoh hsteoh at quickfur.ath.cx
Sat Mar 24 16:59:44 UTC 2018


On Sat, Mar 24, 2018 at 12:11:18PM -0400, Andrei Alexandrescu via Digitalmars-d wrote:
[...]
> Anyhow. Right now the order of processing is the same as the lexical
> order in which flags are passed to getopt. There may be use cases for
> which that's the more desirable way to go about things, so if you
> author a PR to change the order you'd need to build an argument on why
> command-line order is better. FWIW the traditional POSIX doctrine
> makes behavior of flags independent of their order, which would imply
> the current choice is more natural.

So what about making this configurable?

And documented?  Last time I checked, this was not clearly stated in the
docs.


[...]
> > My complaint about the quadratic algorithm was not in the fact that
> > it's quadratic, but that it exhibited this strange (and annoying!)
> > behaviour, especially since the saner (IMO) non-quadratic algorithm
> > would have been the expected choice in the first place, that would
> > *not* have had this problem. It felt almost like we went out of our
> > way just to make things counterintuitive, with slowness added as a
> > cherry on top.
> 
> I want to be convinced. I think you'd need to build a better case on
> why you consider one behavior intuitive and the other
> counterintuitive.
[...]

Honestly, I've wasted far too much time writing about this on the forum
already.  In the time it took to argue about this, I could have already
written my own version of getopt that does what I want, instead of
fighting with strange design decisions in Phobos.  I'm not going to
waste any more time arguing about this, since, after all, it *is* "just"
getopt().

This was not the only issue I struggled with, as std.getopt has other
design differences incompatible with Posix getopt() that makes it hard
to support the original semantics of a previous C++ project ported to D.
Yes, I could have used Posix getopt() from D, but that requires some
ugly shim code, tons of toStringz/fromStringz, doesn't take advantage of
things like automatic enum conversions, etc., which sux given that we're
in D, not C++.

And given the defensiveness surrounding std.getopt, my conclusion can
only be: dump std.getopt, roll my own.  It's sad, since in general
Phobos design tends to be superior to its C++ counterparts.  But we then
have warts like std.getopt that people refuse to acknowledge is a
problem.  So be it.


T

-- 
In a world without fences, who needs Windows and Gates? -- Christian Surchi


More information about the Digitalmars-d mailing list