
-----------------------------------
the_short1
Wed Jun 28, 2006 11:47 am

[Source] The Debug Class!
-----------------------------------
Just thought i would post something usefull that people could include in their programs. I created it for use with my Pegs FP contest submission.

The Debug Class!
-usage:   "Debug.out (what you want);"
-pass "ToggleDebug" to turn on / off, default is on
-if debug is off when you pass something, it stores it into array
-next time you turn debuging on, it will output all the contents from the array
-bug proof so far, and it handles "null" and "" without problems.
-if debug is off, and youve acumalated 400 entries, it will ditch oldest 100 to save from having excessively huge array at startup, to prevent overflow, as well the dos window has a 300 line max in winXP
-you can pass String, int, float, double, and boolean direct, any other format, pass (""+otherformat)

EXAMPLE:

Debug.out ("HELLO1"); // outputs normally cuz debug is on
Debug.out ("ToggleDebug"); // turn it off
Debug.out ("HELLO2"); // this isnt outputed to screen right away
Debug.out ("HELLO3"); // this isnt outputed to screen right away
System.out.println ("intermediate"); // proves its outputed before hello 2&3
Debug.out ("ToggleDebug"); // turn debugging back on

---- this is what gets outputed ---

HELLO1 // first line when debuging was off
ToggleDebug // tells you debuging was toggled (off in this case)
intermediate // notice hello 2 and 3 werent outputed yet!
ToggleDebug // debuging was switched, output anything stored in array
HELLO2 // output from array
HELLO3 // output from array

Check out TestDebug for more examples..

Hope it is of use to some of you, and Debuging is one of the most usefull tools while programming, it allows you to track down errors and glitches in your program very easily. I include at least 1 debug statement per method, and for most GUI actions (eg clicking a button)

Any questions, feel free to post em (but i will be out of town for next few days)
-Kevin

-----------------------------------
wtd
Wed Jun 28, 2006 6:23 pm


-----------------------------------
My first impression:

Put your comments above the line they refer to, and make sure no line exceeds 80 lines.  This is a mess to look at and try to comprehend.  Nevertheless, I shall try, so I can make constructive remarks.

Next thing I notice:

Your conditionals.  Sometimes you use braces, and sometimes none.  Choose a consistent style, since it makes disambiguation much easier.

Structure your code such that you're not just using static methods and fields exclusively.  Have the user of the code create and work with instances of the Debug class.  Which reminds me... if you do that... choose a noun name for your class.

Having to send a special string to toggle the value of a field seems very hackish.  Wouldn't it be better to just have a method which does that?

Integer.toString(num)

-----------------------------------
the_short1
Wed Jun 28, 2006 8:12 pm


-----------------------------------
Me = My first impression:

Put your comments above the line they refer to, and make sure no line exceeds 80 lines.  This is a mess to look at and try to comprehend.  Nevertheless, I shall try, so I can make constructive remarks.
Integer.toString(num)

