4 ms·
The problem with this argument is the low hanging fruit. EXIT is pretty unambiguous. I HATE that some tools the help argument is -? and others use --? when ever
by burnte 3y ago
The problem with this argument is the low hanging fruit. EXIT is pretty unambiguous. I HATE that some tools the help argument is -? and others use --? when everyone COULD just print help on both is maddening, especially when you use the "wrong" one and it just says "do the other for help". You KNEW what I wanted, and didn't do it, just like the article says.
Yes, mindreading is tricky, but sometimes you don't need to read minds to just work with the user.
- breischl 3y agoThe problem is that all the "do what I mean" examples become part of the spec, and then have to be supported forever. Whereas "prints an extra-informative error" is much easier to change. Even for low hanging fruit. eg, `exit` in Python can be redefined as a variable - so if I do that and then type `exit`, should it print that value for me or quit the REPL? Is it better to guess, or just not encourage the user to do the wrong thing? If I make `-?` print help, what happens when I want to define `-` as "read the following text as input" and then users start getting bizarre behavior instead of the help file? You can probably come up with ever-fancier ways to work around this, but that takes effort, and more testing, and more code...
- Hizonner 3y ago> If I make `-?` print help, what happens when I want to define `-` as "read the following text as input" and then users start getting bizarre behavior instead of the help file? I'm not sure what that means, but if you're saying that you would want your program to interpret "-?" as though somebody had run it with no option at all and then provided a question mark on the standard input, that's really obnoxious and grounds for torches and pitchforks from all users. Look, on a command line, a bare hyphen, given as an argument where there might otherwise be a filename, can reasonably mean "read from the standard input" or "write to the standard output", but only because it's been so common for so long. As an alternative to it, you can just use standard input/output by default, or you can just punt and make the user give you something like "/dev/stdin". In any other context, a hyphen introduces an option that modifies normal program behavior. If it's a single hyphen, then the option name is a single character. If it's a double hyphen, the option name is the rest of the argument up to any equal sign. It should consist of complete words and be in `kebab-case`, not `snake_case`. But even if you violate those rules, it's a far more basic rule that an argument starting with a hyphen is an OPTION NAME, not arbitrary data. And the options "-h", "--help", and I guess maybe "-?" and "--?" are pretty much universally used to mean "print help about how to use your program". Changing that is insane. I know that code on on Windows does horrific stuff (including pretending it's freaking RSX-11 and using slashes of all things). I know that some really old UNIX stuff written in the bad old days also breaks the rules. But even those don't just arbitrarily redefine what the hyphen means. Redefining absolutely everything under the user, to the point where they can't even guess how to ask for help, is just crazy.
- Hizonner 3y agoWait what? It would never occur to me to try to use a question mark as a command option at all. That's what "--help" is for. I'm actually surprised any program at all recognizes either form of the question mark. ... but don't get me started on people who think it's ok to use a single hyphen to start a multicharacter option, or don't let you put multiple single character options after the single hyphen...
- nneonneo 3y agoWindows uses /? as the standard help flag, so maybe there are tools that are ported from that convention? -h/--help are all I ever see in macOS CLI tools, in any case.
- JohnFen 3y agoI believe /? started well before Windows, with DOS. IIRC, it was used because -? was common with Unix and CP/M (and DOS is basically half Unix and half CP/M) -- but Microsoft made the decision to have '/' be the switch character rather than '-'. So, /? was inherited from what came before, just slightly modified.
- JohnFen 3y ago> It would never occur to me to try to use a question mark as a command option at all. That's what "--help" is for. -? has been a common switch for decades. I've been implementing it (along with the synonyms -h, --help, etc.) in all of my programs since about the '90s.
- bvisness 3y agoAnything a user tries to do to ask for help is correct behavior that you need to support. It is a crime to tell the user “you asked for help incorrectly”. I suggest supporting at least all of the following: -h, -help, --help, -?, /h, /?, help, <no flag> (if possible). Other flags don’t have to follow these rules, but I think help can be an exception. And maybe you should print the help any time the user enters a bad command.
- 3y ago
- zem 3y agoi agree about the help flags, but not about `exit`, given that `exit()` is implemented as a function and not a repl builtin. python functions do not get run unless called with `()` and it's not worth introducing that inconsistency in there.
- fsckboy 3y agoexit() is unambiguous, syntactically and semantically. exit is unambiguously broken syntax, it doesn't fit into what the REPL promises, it's an error. newbies to unix need to learn about Ctrl-D, and it should be taught. But it should not be the job of every tool to teach that lesson, it's one step removed from QWERTY. There are actually apps that break Ctrl-D and they are another abomination in the direction of newbie hand holding.
- ryandrake 3y agoThe worst is a few tools where when you type: the_command -foo ...and the tool responds with: -foo: No such option. You probably meant --foo Well shit! Thank you for that burst of empathy. If you, developer, are that confident that's what I meant why couldn't you just make both inputs do the same thing? You went out of your way to make the code handle -foo, but only to have the program fire off that snide remark instead of doing what you know the user meant to do. Maddening.
- Ntrails 3y agoGiven the number of times I run git psuh To be told "you probably mean push"... yeah it'd be easier for me if they went ahead and accepted the typo :D
- Joker_vD 3y agoJust add [alias] psuh = push to your ~/.gitconfig? I personally have "ull = pull" and "ush = push" in this section, together with "alias gitp='git'" in my ~/.bash_aliases because of how often I type "gitp ull".
- Ntrails 3y agoI have "st = status" but you're absolutely right I should probably get around to updating!
- rrobukef 3y agoBecause you may have meant --f=oo or -f -o -o, both of which are standard unix interpretations of single-dash multi-character flags (e.g. ls, ssh). Or maybe the newest version added the -foo flag. And if you've got something like 'sed' overwriting the input file (-i), it'd better make sure the flags are exactly as documented.