News for hackers. Stuff that matters.
Re:Why Isn't Debugging Treated as a First-Class Activity? by zamalek on Wednesday July 11, 2018 @12:11PM (#17508011)
> WHY

If a developer doesn't check for a null value, are you really going to head to the documentation to find out why? Is the segfault really by-design? It might sound facetious, but that's the 90% of bugs: not specifically segfaults, but trivial mistakes, invalid values and logic problems. Only a debugger can show you the steps and conditions involved that lead to that invalid value. Sometimes, through debugging, you find a problem that does span multiple layers or components.

If something spans multiple layers or components then that's a design problem. When you are solving a bug like this you have to "debug" at a much higher abstraction level. You shouldn't use a debugger for this (as you've pointed out); you should use a team of peers (documentation alone is not the correct tool). That team might rely on documentation, but would have to keep in mind that documentation rots over time.

If you're solving the former with the processes of the latter, I'm surprised you get anything done. Documentation won't tell you where an invalid value originates from or why. Only extremely verbose logging or debugging can do that.

Re:Why Isn't Debugging Treated as a First-Class Activity? by wolfgke on Wednesday July 11, 2018 @12:33PM (#17508215)
> If a developer doesn't check for a null value, are you really going to head to the documentation to find out why?

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.

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.
Re:Why Isn't Debugging Treated as a First-Class Activity? by wilun on Wednesday July 11, 2018 @02:20PM (#17509059)
> Only a debugger can show you the steps and conditions involved that lead to that invalid value.

No. Static analysis can and is actually what is used most of the time. Either with an automated tool, or with your brain.

Of course debugging is also needed, but the right mix between the two is needed, and you are actually doing it even if you use a debugger a lot (at least I hope so, otherwise you are probably not fixing your bugs correctly way too often).

Re:Why Isn't Debugging Treated as a First-Class Activity? by codedokode on Wednesday July 11, 2018 @06:48PM (#17510845)
But is not breaking into a debugger and seeing the call stack often faster? Brain won't help you much if you have thousands of files and more than 100 000 LOC and with the debugger you just walk up the stack until you see where that NULL came from. And after fixing the bug, of course you can use your brain and search for similar code patterns to make sure that there is no same mistake anywhere else.