Lost in Debug Hell : Fix Your Messy Trace Commands!

I've done some collab coding work as well as plenty of my own projects and if you have done the same you would probably agree that debugging can be one of the biggest tasks that we as programmers have to face in our projects.

Usually proper debugging consists of many many trace statements until we are able to pinpoint areas that aren't doing exactly what it is that we want our code to be doing. Well, one problem that I have run along many times within my own code and more so when working with other people's code is the problem of not being able to find trace statements and / or not knowing where a particular trace statement came from!

Take for example a case where you decided to trace out the "health" of your hero each time he is hit so you can make sure some enemy attacking code is working properly. You will obviously see in your trace window some arbitrary number each time you are attacked and that will make sense at the time...however look at this example here:

In this case, if you (or someone else) were to come to this code later you may have no idea what is being traced out, or where the traces are coming from. (if you are curious...it's outputting the FPS) This is very frustrating and messy, and can waste a lot of time. So what is the solution? Well really it just lies in using good practice. You should always label your trace statements so that it is apparent where they came from and what they are outputting. Basically I enclose the trace text with the following format:

 Label: Value

It will look like:

As you can see it is much easier to read.

Anyway, as I said this is more of a "standard" much like any other coding standard which may SEEM like extra work at the time but it will save your headaches in the end. Trust me!

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5 out of 5)
Loading ... Loading ...

2 Comments so far »

  1. Scott Delamater said

    am June 3 2008 @ 9:26 am

    Excellent point! This alone can save someone hours of work.

    A related convention I use in cases where I may be debugging a particularly complex function (i.e., many trace statements in one function) is to trace the class/method name once, then indent subsequent trace statements:


    public function myComplexFunction ():void
    {
    trace( “” );
    // crazy stuff happens here
    trace( “\tmyValue: “+myValue );
    trace( “\tmyOtherValue: “+myOtherValue );
    }

  2. Scott Delamater said

    am June 3 2008 @ 9:31 am

    err…what looks like:

    trace(”");

    in the prev comment should be:

    trace(”<MyClass.myComplexFunction()>”);

Comment RSS · TrackBack URI

Leave a comment

Name: (Required)

eMail: (Required)

Website:

Comment: