4 ms·
It's really a Googleism that was inherited by Go. I remember their open source C++ command-line library did the same thing.
by ericbarrett 6y ago
It's really a Googleism that was inherited by Go. I remember their open source C++ command-line library did the same thing.
- kevinmgranger 6y agoIt's originally from Plan9, which predates Google.
- naikrovek 6y agotoo few people understand this. Go was designed by former Bell Labs people who worked on Unix, Plan9, or both. many things about Go that people attribute to "googlism" is really attributable to work done at Bell Labs.
- QuercusMax 6y agoIn my experience at Google, only Go does flags like this. Everything else (python, java, c++, blaze) all use the same flag syntax, which is all via long args with two dashes.
- ben0x539 6y agoThis seems pretty "standard": https://fuchsia.googlesource.com/fuchsia/+/master/docs/concepts/api/cli.md#command-line-arguments https://fuchsia.googlesource.com/fuchsia/+/master/docs/conce... Is it based on Google's internal preferences?
- QuercusMax 6y agoTBH I have no idea; I've heard of Fuchsia, but know nothing about it. It seems pretty far removed from the majority of work I've done in Google3 (the monorepo).
- tdeck 6y agoI have seen a mix. For example, many Android developer tools (not written in Go) use this single-dash style. I believe the standard libraries used for parsing in internal tools mostly support both syntaxes, although some docs do describe the old single-dash style by default.
- re 6y agoThe Java ecosystem has historically used single-dash options, both the SDK tooling (e.g. `java -jar`, `javac -classpath`) and classic common libraries like Jakarta Commons CLI. It has moved away from it more in recent years so now you get a mishmash of single and double dashes depending on how old the option is. In some cases you end up with stuff like `java -showversion` which prints the version to stderr but ` java --show-version` which prints to stdout.
- TeMPOraL 6y agoPowerShell picked up the single-dash flag syntax too.
- coldtea 6y ago>many things about Go that people attribute to "googlism" is really attributable to work done at Bell Labs. We're 50 to 30+ years away from that Bell Labs work. They could have checked what happened in the meantime with the rest of the computing world, before re-imposing obsolete ways with the full power of Google behind them...
- 4ad 6y agoNo, Plan 9 doesn't have long options at all.
- GongOfFour 6y agoI was going to say, it seems like something Google tooling prefers, even non go tooling.
- jeffbee 6y agoGoogle's command line flags library, known to the public as absl::Flags and formerly gflags, does not distinguish between --foo and -foo, these are both the flag "foo". Each flag has a unique name so there is never a short -f equivalent to --foo, and -foo can never mean -f -o -o. The main design motivation of absl::Flags is that the flag definitions can appear in any module, not just main. Go inherits this. A quirk that Go did not inherit is gflags --nofoo alternate form of --foo=false. This is all documented at https://gflags.github.io/gflags/#commandline https://gflags.github.io/gflags/#commandline, which is pretty much a verbatim export of the flags package documentation that a Google engineer would see internally.
- MereInterest 6y ago> The main design motivation of absl::Flags is that the flag definitions can appear in any module, not just main. Well that's kind of horrifying. That means that command-line arguments are a form of global state, and can silently alter the behavior of the program without the calling scope noticing. I'm kind of vary of these mechanisms, because I've been bitten by them before. There was a python library I used that read its configuration from sys.argv the first time an object from the library was constructed. I had a rather painful time debugging to find that my script accepting a -b argument resulted in the library switching to batch mode and suppressing all graphics. Dang it, those were my arguments, and the library had no right to go behind my back and look at arguments that hadn't been directly provided to it!
- jeffbee 6y agoIf you think that's horrifying, what if I told you that a sufficiently-entitled operator of a given program can alter the flags at runtime ... using their web browser. https://twitter.com/jbeda/status/888635505201471490 https://twitter.com/jbeda/status/888635505201471490
- MereInterest 6y agoOh my. I have a gut feeling that I don't like it one bit, though I tend to be a bit more generous on logging. Logging is one of the only cases where its presence or absence don't change the inputs or outputs of any function, nor any other observable effect of the program. Having or removing logs doesn't impact the testability of a function, unlike any other use of global configuration.