5 ms·
Yep, I wrote a bunch of C macros to prevent them and use them everywhere: curl http://zedshaw.com/dbg.h http://zedshaw.com/dbg.h The main thing that caused de
by zedshaw 16y ago
Yep, I wrote a bunch of C macros to prevent them and use them everywhere:
curl http://zedshaw.com/dbg.h http://zedshaw.com/dbg.h
The main thing that caused defects was not handling default cases in logic. Things like not filling in the dangling else of an if-statement, not trying to return a value from a function no matter what, and not having a default: in a switch. By always trying to include at least a comment there, or an assert it forces you to think about the logic of the whole statement and prevents bugs galore. Combine that with unit tests and you've got a good solid start.
I don't recommend it because it's an insane amount of work above just writing code. I think it'd be something I'd force on high speed students in a kind of "Boot Camp" situation, but not on anyone else. In fact, I think most programmers couldn't handle having a giant bag of evidence staring them in the face telling them they suck. Also I think most programmers wouldn't get the stats behind the analysis and just keep screwing it up.
I play guitar when I have to think about stuff. I take one to work, and when I'm stuck I bust out my guitar, a pen, and a note pad. I then noodle and practice, and as ideas come into my head I write them down without filtering.
Basically, you need a hobby. :-)
- agazso 16y agoIn most recent C compilers you can turn on warnings for at least missing return values from functions and not having a default: in a switch. It is good practice to compile C/C++ programs with high warning level, and fix all the warnings before shipping.