special debugging lines (java)
Posted
by David
on Stack Overflow
See other posts from Stack Overflow
or by David
Published on 2010-04-24T01:43:29Z
Indexed on
2010/04/24
2:03 UTC
Read the original article
Hit count: 313
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 anif(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).
© Stack Overflow or respective owner