I Flock

Thursday, April 24, 2008

Bugged by bugs

Some bugs are just so frustrating to find :) After spending a full day hunting down a bug, when I finally find it, its so simple I feel like running head first into a wall for being so dumb. I even got to a point yesterday where I started searching through my old backup files to see if I had overwritten a more up to date version of the code. Oh well.

A few tips for budding developers on how to prevent bugs in your code.

1. Don't drink coffee all day and hope that it won't effect your thinking, it will, and you will wonder what the hell you were thinking when you go back to the code later.
2. Keep it simple. I know its been said many time before, but its correct, you must keep it simple. Let the compiler make your code small, that is its job, not yours. If you have say for example a=1*(1/b)*(c/4); split it up, and comment it. You will appreciate it when you get back 6 months later to do an update. That's a simple example of course :)
3. Don't expect code written at 3am to be correct. Your tired even if you think your not. Trust me.
4. Stick to a strict coding style. Comment a lot, and don't comment such things as a=(1/b); // divide 1 by the value in b. That tells you nothing. Whats b? you may know what it is now but what about 6 months time. You should of course be using more memorable variable names anyway. Like I said your code will be compiled or interpreted by the compiler you don't have to do the job of the software.
5. Keep your code tidy, this is aimed at C based languages. You do NOT have to fit everything into one line. If you are adding something then checking its value, add in a variable, compare in an if, don't do this all in the if statement. Why? Well try debugging that when you have a problem.

Well thats it for now. Those are my rant points :)

On the puke bus tomorrow. More bugs to find.

No comments: