4
micnil
6y

Argument exception message convention: is it better to specify what is allowed or what is not allowed? Eg: "value must be a positive integer" or "value can not be negative"?

Comments
  • 2
    People don't tend to get negations wrong if they aren't used that much. If you have to read this sentence more than one time to be sure, then you know why you should use positive wording wherever possible.

    With the example, be sure to specify what about 0.
  • 1
    I would try to make it dependant on why the function needs the requirement. With your example: If passing a negative number wouldn't make any sense, like when used as an amount, the number "can't be negative". But if it's just the function's inability to cope with a negative number, the number "must be positive" (for example a square root function that can only calculate positive roots).

    This is just a non-native speaker's opinion though. I think it would be fine to use only one of these two variants everywhere.
Add Comment