The best debugger is a good compiler
The title of this post is a quote from a programming course I’m taking at the moment that really made me think about things differently. In this course we’ve been doing fairly low-level programming in C, which is quite different from most of the programming I’ve been doing recently. One of my biggest lessons from the course was:
Get the compiler to catch the bugs before you even run the code then you don’t have to
In my assignments for this course there have been so many bugs that I’ve caught by setting the compiler to be a bit stricter. In fact, it’s amazing what compilers these days can do. The latest versions of compilers such as gcc will do an awful lot of what tools like lint do – checking things that might be a problem and letting you know about them. So – Rule 1 is to make sure you’re using a fairly up-to-date version of your compiler, as the ability of compilers to find problems in your code has got a lot better recently.
Rule 2 is to set your compiler to be stupidly picky and it will, honestly, make your life easier. For us gcc people that means rather than running:
gcc -Wall -pedantic source.c
It’s only a few more characters typing (no extra characters if you put it in your makefile) and can make your life a lot easier.