Subscribe to andrewsw's Blog        RSS Feed
****- 1 Votes

Debugging with Custard

Icon 5 Comments

The Fast Show said:

Debugging is very much like making love to a beautiful woman..

Well, it's not really. It is more like trying to discover fundamental particles. You throw all kinds of custard at it in the hope that something sticks. Well, not custard, but other high-energy particles/radiation. And you are not hoping that something will 'stick', but for evidence of new particles. Not a particle itself: it is not going to jump up and say "Here I am!". You are looking for remnants, a history, a trace of the particle.


I assume that boffins eliminate all the known-knowns first. That is, they remove the traces that are expected, or understood, eventually identifying the traces that are, as yet, unexplained. Debugging is kinda similar (sort-of..).

When debugging, especially when you are relatively new to it, it is acceptable to throw all kinds of custard. But some basic steps are:

  • Split complex statements into individual lines.
  • If necessary, introduce new variables to store intermediate values.
  • Print out the values of your variables. Use messageboxes or console-print statements. (In Visual Studio you can print to the Immediate Window using Debug.Print.)
  • Introduce temporary, test values, that you know should work.

Try anything that occurs to you. Anything that might yield a clue, or at least eliminate some possibilities.

More formally, you need to become familiar with the debugging tools of your editor of choice. You will then be able to step through your code, examining all variables as you proceed, often being able to test expressions. I have a tutorial for VB.NET:

Debugging in VB.NET
(There is an equivalent pinned in the C# tutorials section.)

Debugging is an investigative process. You are not necessarily looking for a direct answer to a direct question. You are looking for clues to the whereabouts of Mr, or Mrs, Error.

As you become more experienced you will be able to target, and refine, your debugging steps. To get to this level though, be willing to try anything and everything!

More experienced programmers fall into a different trap. They tend to over-confidence and can miss some very obvious things! (I speak from experience..)

The clues you uncover will eventually lead you to the problem and, hopefully, the/a solution. Once the problem is found you can then, of course, take him (or her) into, erm.., custardy (Groan).

5 Comments On This Entry

Page 1 of 1


19 December 2013 - 01:28 PM
Another good debugging aid, or at least the way I see it is Option Strict (When you don't usually have it on). I used Option Strict and while writing code, it won't let me compile things that could cause problems. I tend to take someones code and the first thing I do is insure Option Strict is on (by physically putting Option Strict On in the code window.) Then when those little lines start showing up, they're the first place I begin looking. Not that they are always the cause, but when they are it's a nice aid in speeding up the search process. I know there are still a lot of new programmers that are intimidated when their code runs and seems to work and then they one day someone tells them "you should turn on Option Strict" and Bam, squiggly lines everywhere. "Um, let's turn that back off" and then their next statement is "Hey why isn't my program giving the proper results?". Anyway, it's too bad blogs don't get reps, the custardy line was worth one in my opinion :D


19 December 2013 - 03:49 PM
Thanks Charlie ;)

Just to note (for other readers) that Option Strict On is for VB.NET. It can also be set as the default setting from Tools, Options, Projects and Solutions, VB Defaults (or similar).


20 December 2013 - 11:14 AM
I've inherited a project at work, I'm using VS2013 which defaults to Option Strict On.
It give up listings the issues after 104 of them. So it Option Strict Off (for now while I de-crappify the code base.


21 December 2013 - 06:24 AM

Charlie said:

Anyway, it's too bad blogs don't get reps, the custardy line was worth one in my opinion

It is more about the Voting stars at the top for Blog entries.


21 December 2013 - 08:16 AM
CharlieMay If the blog post's author reply to the post, it is possible give rep by up-voting (or down-voting ) that.
Page 1 of 1

Trackbacks for this entry [ Trackback URL ]

There are no Trackbacks for this entry

December 2020

  1 2 345


    Recent Entries

    Recent Comments

    Search My Blog

    0 user(s) viewing

    0 Guests
    0 member(s)
    0 anonymous member(s)