6 ms·
Yet another tragedy broughtabout by golang (at least in part)! :) (https://golang.org/pkg/flag/#hdr-Command_line_flag_syntax https://golang.org/pkg/flag/#hdr-C
by ben0x539 6y ago
Yet another tragedy broughtabout by golang (at least in part)! :)
(https://golang.org/pkg/flag/#hdr-Command_line_flag_syntax https://golang.org/pkg/flag/#hdr-Command_line_flag_syntax)
Edit: To be clear, I'm mostly "blaming" Go for re-popularizing this style by a) putting it in the standard library and b) being a widely used programming language; I'm not saying Go came up with this or anything.
(idk about the space separated args tho that's even worse)
- ericbarrett 6y agoIt'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.
- ainar-g 6y agoI think Go's package "flag" was partially inspired by the one made by Apache for Java, but I can't find any sources confirming that now, so I might have seen that in a dream, heh.
- Blahah 6y agoIt predates golang significantly. C and C++ bioinformatics tools have used single dash long opts since the 1990s, unfortunately. I expect the transgression didn't originate in the bioinformatics community.
- COGlory 6y agoI'd always assumed that was because people without significant deckers experience on a terminal are far more likely to type -help than --help or -h
- attractivechaos 6y agoSingle-dash long options are not started in Bioinformatics, but they are more often used in this field than elsewhere. Perhaps that is partly because some of the most popular tools (e.g. blast, muscle, bedtools and gatk) followed this unfortunate convention.
- hnjst 6y agoCobra (https://github.com/spf13/cobra https://github.com/spf13/cobra), which is a pretty popular library for Go CLI applications, behaves more like classical GNU tools. It also offers usage/help autogeneration and autocompletion for popular shells. Not sure about the relevant point on compact short options syntax as in `tar -xvzf archive.tgz` though... (edit) after a quick & sloppy test it seems to work as expected
- ben0x539 6y agoYeah but `tar xvzf archive.tgz` also works so I remain wary of tar. Basically every time I have tried to do something that's not tfz or cfz or xfz, it went wrong until I checked the manpage.
- hnjst 6y agoRight. I probably picked one of the most flaky examples, sorry for that. Let's say `ls -lah` that (I hope...) is less ambiguous. In my defense, the specific example I gave is valid for both GNU and BSD versions of tar. If I understood correctly, the issue you point to (order among short form flags) is related to the fact that `f` expects an argument and consequently has to appear in the last position.
- ben0x539 6y agoAh, it's not a direct argument when you omit the hyphen and fall into "traditional" mode. I think after years and years I can finally wrap my head around how that works. :D
- chrisweekly 6y agospeaking of `man`, why can't it be more like `tldr`?
- hnjst 6y agoI guess you could consider https://github.com/tldr-pages/tldr https://github.com/tldr-pages/tldr. I personally wouldn't touch that, but that's related to my allergies to JS ecosystem and predisposition to panic attacks when I see stuff like that https://github.com/tldr-pages/tldr/blob/master/package-lock.json https://github.com/tldr-pages/tldr/blob/master/package-lock.....
- deleted 6y ago[deleted]
- Seb-C 6y agoI found it surprising too that the native library in Go does not follow this standard. Fortunately, there are alternative packages that does.
- mseepgood 6y agoIt's by Ken Thompson, who invented Unix, so it's ok.
- toyg 6y agoI think Powershell does it too.
- deleted 6y ago[deleted]
- CogitoCogito 6y agoOne thing go's flag's package does that deserves a lot of blame is to automatically sort the flags alphabetically when looking at -help. And the fact that you need to hack your away around it instead of there being simply an option like nosort=true or whatever is even worse. The whole idea is crazy and basically equivalent to the statement that there order of parameters in -help serves no useful purpose.
- Cthulhu_ 6y agoAnd yet, I expect flags to be sorted in a man page; I rarely read things in a logical order, I'm just looking into what flag does what. It's a convention-over-configuration thing I think. I mean they set a standard, so you can move on. The alternative is to sit and think and discuss about what order to put your documentation in.
- ljm 6y agoYou read text from top to bottom. Chances are that you're writing help text and describing the most commonly used flags at the top, and the more obscure ones lower down.
- josefx 6y ago> I'm just looking into what flag does what. So you read the whole man page when you need a flag that does something specific or do you mean you never write new things and just have to look up flags already in use by some script? Because for everything else that seems like a fascinating waste of time.
- _ZeD_ 6y agoif I'm searching I'm... searching: like using grep with some keywords. Why order of the parameters should matter in this case?
- josefx 6y agoBecause you don't always know which words the man page uses to describe specific functionality. So many ways to express similar ideas, language is fun that way.
- rollcat 6y agoThankfully we have git.sr.ht/~sircmpwn/getopt github.com/pborman/getopt github.com/mattn/go-getopt rsc.io/getopt and a hundred more, but I really wish getopt was a part of the standard library.