Hacker News new | ask | show | jobs
by foobarbaz1234 4254 days ago
I am not so sure with that. Say, your program is used in a shell script and is invoked badly - you might want to print its usage then. If you exit normally your shell script might break weirdly but if you exit with error it's easier to spot the reason of failure.

On the other hand you made me thinking and probably you should have three code passes per default:

  [0] normal behaviour (exit 0)
  [1] bad arguments (exit EINVAL)
  [2] --usage (print to stdout but but exit != 0)?
Anyway I am not sure if it makes sense to declare "usage" as normal behaviour.
1 comments

In my book, there is a difference between explicitly asking for help/usage and passing arguments that do not make sense, which triggers the output of help/usage.

The former, I think, should write to stdout and return 0, the latter should write to stderr and return something non-zero.

Giving help if the user asks for it is normal behaviour.