logoalt Hacker News

spider-mario • today at 6:35 PM • 0 replies • view on HN

> The line between what's "input validation" and what's "What you expect" is very muddy. Input validation is a statement of "this is input I expect".

> Is it input validation to say a string must be at least some length characters? What if that string is a password? What if it's an MD5 sum?

Think of it this way: pre-conditions are what the function assumes to be true when it’s called. If it would not be justified to make that assumption at the point where the function is called, it is the responsibility of the caller to perform a runtime check to ensure that it applies. So you might well have a precondition at the level of the function and an explicit check of the exact same condition on the caller side to ensure that it’s respected. If the caller fails to ensure that the condition is fulfilled, and the precondition thereby trips, that’s a programming error.