3 ms·
No it isn't. In my experience, there are few higher quality signals a codebase is utter garbage than having `if (arg == NULL)` checks at the top of every functi
by jcalvinowens 3y ago
No it isn't. In my experience, there are few higher quality signals a codebase is utter garbage than having `if (arg == NULL)` checks at the top of every function... Almost nothing in libc does that, it is entirely unnecessary.
I realize that wasn't your point, but this is an enormous pet peeve of mine...
- UncleMeat 3y agoA dereference is an implicit "I will crash and burn if you hand me null" contract.
- jcalvinowens 3y agoYes, exactly. Nobody should be surprised that calling `strlen(NULL)` crashes. Checking for NULL at the top of strlen() would be stupid, which is why it doesn't do that. I've seen a lot of so-called "enterprise" code does that, and it's absolutely idiotic.
- UncleMeat 3y agoOkay. But that's totally unrelated to my original point, which is that we are already very used to functions that do not accept the full domain of a given type. "I don't accept nullptr" is not too fundamentally different from "I don't accept "0x8000..."
- kazinator 3y ago"I don't accept {nullptr, 0x8000}" is fundamentally different from "{nullptr, 0x8000} is a trap representation". If it's a trap representation, you can't even pass it to me so that I could accept or reject it.