debugging scaffolding contingent upon degbugging boolean (java)
- by David
Recently i've found myself writing a lot of methods with what i can only think to call debugging scaffolding. Here's an example:
public static void printArray (String[] array, boolean bug)
{
for (int i = 0; i<array.lenght; i++)
{
if (bug) System.out.print (i) ; //this line is what i'm calling the debugging scaffolding i guess.
System.out.println(array[i]) ;
}
}
in this method if i set bug to true, wherever its being called from maybe by some kind of user imput, then i get the special debugging text to let me know what index the string being printed as at just in case i needed to know for the sake of my debugging (pretend a state of affairs exists where its helpful).
All of my questions more or less boil down to the question: is this a good idea? but with a tad bit more objectivity:
Is this an effective way to test my
methods and debug them? i mean effective in terms of efficiency and not messing up my code.
Is it acceptable to leave the if
(bug) stuff ; code in place after
i've got my method up and working?
(if a definition of "acceptability"
is needed to make this question
objective then use "is not a matter
of programing controversy such as
ommiting brackets in an if(boolean)
with only one line after it, though
if you've got something better go
ahead and use your definition i won't
mind)
Is there a more effective way to
accomplish the gole of making
debugging easier than what i'm doing?
Anything you know i mean to ask but
that i have forgotten too (as much
information as makes sense is
appreciated).