“The general rule of thumb is that it takes $10 to fix the bug during development; $100 to fix the bug in QA; a $1,000 to fix the bug during beta testing; and $10,000 or more to fix the bug post-deployment.”
I pretty much agree with that. Not to those specific numbers, just to the fact that it’s a pain to fix stuff after the fact. So when developing you should take your time and double-check your code when you’re finished. Then have a peer review it and make sure it’s perfect.
But there’s no way you’re going to catch all the bugs. So to make debugging easier you should always have really good error handling and error logging. Check for and log every error possible. That means looking at the return value for every system call. If an error can happen then assume it will happen.