Command line parsing
Andrei Alexandrescu via Digitalmars-d
digitalmars-d at puremagic.com
Mon May 2 05:52:42 PDT 2016
I found this in https://peter.bourgon.org/go-best-practices-2016/:
"I said it in 2014 but I think it’s important enough to say again:
define and parse your flags in func main. Only func main has the right
to decide the flags that will be available to the user. If your library
code wants to parameterize its behavior, those parameters should be part
of type constructors. Moving configuration to package globals has the
illusion of convenience, but it’s a false economy: doing so breaks code
modularity, makes it more difficult for developers or future maintainers
to understand dependency relationships, and makes writing independent,
parallelizable tests much more difficult."
This is interesting because it's what std.getopt does but the opposite
of what GFLAGS (http://gflags.github.io/gflags/) does. GFLAGS allows any
module in a project to define flags. I was thinking of adding
GFLAGS-like capabilities to std.getopt but looks like there's no need
to... thoughts?
Andrei
More information about the Digitalmars-d
mailing list