3 ms·
Failure semantics are just as important as happy-path semantics. Good languages are fail-stop. The case I'm thinking of was some linux kernel code that looked
by lmm 7y ago
Failure semantics are just as important as happy-path semantics. Good languages are fail-stop.
The case I'm thinking of was some linux kernel code that looked roughly like:
void checkBeforeDangerousThing(SOMETHING* detailsPtr) {
SOMETHING details = *detailsPtr;
if(detailsPtr == null) return;
if(!isValid(details)) return;
doDangerousThing();
}
The intended semantics of that are pretty clear. There are two defensible implementations for this code if detailsPtr is null (hence why it was left undefined in the C standard): either it should return cleanly without calling doDangerousThing, or it should trap on the invalid null pointer dereference (possibly asynchronously). What no reasonable language community would consider to be a reasonable implementation - what only an adversarial reading of the standard reveals is even an option - is to execute doDangerousThing() when passed a null pointer.