31 ms·
Sometimes your methods ask for permission. Every parameter is validated at the top of the function and errors are thrown if any parameter is wrong, e.g. null p
by snarfy 8y ago
Sometimes your methods ask for permission. Every parameter is validated at the top of the function and errors are thrown if any parameter is wrong, e.g. null parameter checks. Generally this happens inversely to the amount of trust in the caller. A public web service call would have everything strictly validated.
Sometimes your methods ask for forgiveness. For sake of argument, they accept a bunch of pointers as parameters and blindly start dereferencing them without any null checks. This is done because it is a small implementation and the caller is completely trusted and is known as fact they would never be null. Those checks are redundant and a performance cost.
It's really a judgement call to known when to get permission and when to ask forgiveness.