Re:Why Isn't Debugging Treated as a First-Class Activity?
by tkxxx7 on Wednesday July 11, 2018 @01:23PM
(#17508619)
I mostly agree with this sentiment, but I find it a bit friendlier to other developers to assert(x not null) in most languages, at least so that they can find out sooner that the error is, in fact, their fault.
Re:Why Isn't Debugging Treated as a First-Class Activity?
by laythea on Wednesday July 11, 2018 @05:16PM
(#17510354)
How do you know if you made a programming boo boo unless you do a null check...
if (value == null) print "Must try harder"
?
Re:Why Isn't Debugging Treated as a First-Class Activity?
by dotancohen on Wednesday July 11, 2018 @01:06PM
(#17508469)
I hope that you're leaving a comment in the function noting why you think that NUL should not be checked. Also, depending on the field, you might want to consider defensive programming.
Re:Why Isn't Debugging Treated as a First-Class Activity?
by wilun on Wednesday July 11, 2018 @02:24PM
(#17509083)
The meaning of "defensive programming" is highly contextual even within a given "field". Also, major influential parts of the industry (last example in date being the C++ committee) are moving away from indistinct checks and exceptions, and toward contractual programming.
Yes. I often write code in a way such that no null is checked. But if I do so, I always document it properly and my reasoning why, if the function is used properly, no null will be passed.
This way, you can be sure that if a null is dereferenced, not my function is the source of the bug, but a function that does not obey the pre-invariants that my function imposes on its parameters.
So you know that you are not supposed to "fix" this bug by introducing a null check to my function, but instead fix the bug in the other function that calls mine.