Debugging Solutions – A Framework

Recently i’ve been running into numerous bugs occurring in my code, it mostly stems from the fact I am working with another companies poorly written code, planning on helping them out I decided to accept the job without a proper look at their current code, and database structure. Note To Self – Don’t ever accept a job that you don’t see first or create yourself.

Anyway, bugs galore is something that I’ve had to deal with. So I assumed other people would probably be in the same dilemma at some point in the programming lives where they had run out of ways to debug. So I am attempting to write a debuggers framework, particularly for dealing with code from other people. Although this list will apply to any code, your own, others, or a mixture.

Step 1 – Find the bug. This is normally the easiest step :P. Many times someone else will do this for you. Take note of the location of the bug, any error messages it emits, and the variables in the URL. If an error is generated then you have struck a gold mine, this is normally due to a syntax error somewhere in the code, take note of any line numbers that it has given you and continue.

Step 2 – Open up the code and peruse the file. If the file you are working on calls on a number of other pages, or functions from other files open those up as well. As you are perusing look out for the obvious errors, if you have an error code or a line number in which the error has occured check that this line and the line before and after it are syntactically correct.

Step 3 – Still no Luck? Check the logic. Logic errors account for most of my errors especially when dealing with date data types, the way my brain thought about the scenario was backwards or somethign unexpected came through. Check that they are correct do some simple scenarios in your head. If this doesn’t solve the problem, change any changes make to the original.

Step 4 – Google. Need I say more, not really but a couple of tips won’t go astray.

  • Search Terms – Type in the box what you would say if you were asking a fellow programmer. My website is generating broken images when I do such and such. Still no luck be less specific – Images are broken when my page loads.
  • Google Groups. Sometimes a quick search of google groups can give immediate results. Sometimes not.

Step 5 – Take a break – take a 10 – 20 minute break, if you have been working on the bug for more then an hour. Play a game of solitaire or minesweeper to relieve some stress, go get a cup of tea/coffee. Whatever it takes to get your mind off the problem. Dwelling on something is normally the worst scenario to be in.

Step 6 – Feel better? Not for long… If you are at this point and it still needs to be fixed urgently then its time for some commenting of someone elses code, not the best scenario but a very good one.

  • Write your own output function for debugging – See my post on – Spitting – Soothes the Soul and Eases the mind.
  • Use html comments to output some code in the background, this is especially important when you are fixing bugs on a live site. People are unaware anything has changed, but you can continue to debug freely. Well not as free as you would like but fairly unrestricted. If you have a Sandbox type area then use that and only upload changes when you have fixed it.
  • If you aren’t on a live server. You got it made – Die Statements to infinite and beyond. If you are debugging javascript Alert statements are your friend. Before each die statement place a print_r($_GLOBALS) or whichever custom function you made see Spitting Link two points up ^

Step 7 – This is never a good step to be at. Now is about the 2 – 5 hour mark. You are more then likely grumpy, irritated, snappying and any and every living thing and even some inanimate objects. But there is light at the end of the tunnel. Step 8 is go to sleep. But first you should find an appropriate forum that posts similar problems to what you are having. Try to find one that is still active. Put a few posts up on a number of forums then go to Step 8.

Step 8 – Sleep on it. You might toss and turn for 30 minutes while you attempt to break your brains vice like grip on the problem, but now is your subconscious’s time to shine. Ever noticed that your thoughts are clearer in the morning, or you have a solution to the problem you’d been having about how you would begin a project. Daybreak comes, you stir from your slumber, roll out of bed (insert personal wake up routine here), *Ding* Lightbulb, thats an idea! Run frantically to the computer or to a pen and paper and jot down any partial, possible, probable, plausible, portable, pottable, porsche (too many p words) solution that you think up. Driving to work and think up one, use your phone, most phones these days will have some sort of voice recording (not advising using your phone while driving – many phones with recorders have a quick use button.), or pull over and write it down. Forgetting it would be terrible at this point.

Step 9 – Try some of your ideas (if any).

Step 10 – Check your forum posts, any hits, and views, most of all any Replies???? If there are go check them out. If not start again from Step 2.

I know the feeling of desperation when it comes to debugging, mood swings, cussing (worse then a sailor, and if you are navy computer programmer, dear baron that would be some colourful language), all the side effects of a nagging coding issue.

Usually many people will solve their problems by Step 3 – 4. Simply stepping through the code in a calm manner can often prove to be the best approach. Try not to get too rialled up, it’s only code. :>

You can leave a response, or trackback from your own site.

Leave a Reply