What are the expert debugging hints for your favourite language, you think everyone should use?
As an example, I’ll provide my C++ debugging hints, that between them help me shake out most of the bugs I come across, in this often hard-to-debug language.
C++
-
Increase the warning level of your compiler to maximum, then stop those warnings which occur a lot and you’ve decided you don’t care about (for me it’s unused parameters). g++ doesn’t warn about missing return statements in functions (a problem I find frequently) until the warning level is very high.
-
Learn how to turn on your compiler’s debugging standard library, and use it! ( -D_GLIBCXX_DEBUG for g++). This finds lots of errors, and also helps show exactly where the errors occurred.
-
Always, always, always run your code through a really good memory checker, like valgrind, and fix all the problems it produces.
A couple of my own, from spending too many nights debugging stuff that the compiler or runtime environment could have warned me about if I’d used it properly:
Ideally, you should try to catch problems before you need to fire up the debugger – anything you can tweak such that it creates a compilation error is much easier to fix compared to tracking it down in the debugger and then fixing it.