Re: Need help with my logic
- From: Mark Space <markspace@xxxxxxxxxxxxx>
- Date: Tue, 10 Oct 2006 20:08:45 GMT
Martin Gregorie wrote:
3. Diagnostic tracing:
Add a boolean debug variable to your classes to control diagnostic output. Set it either through the constructor or with a separate method:
This is a very good point, and everything Martin says here is true.
This technique is so important, that most languages support it directly. Both C and Java support the assert statement which does the if..then... part for you. (In C, it's a macro, not a statement.)
In Java, the assert statement can be controlled from the command line just as Martin describes. Combine this with the divide-and-conquer strategy, and you can turn assertion on and off in differ parts (chunks) of your program. This allows you to only see asserts from parts of your program, and the other parts run at full speed. (Because the compiler optimizes assert away when it's disabled.)
The disadvantage of assert is that it's less flexible than an if..then... so you'll sometimes still have to use them as Martin describes.
I do disagree with Martin on one point: using a debugger. My preferred method is to use different boolean debug variables for different parts of my program. (Divide and conquer, again.) Then, instead of setting the debug variables on the command line, I set them with the debugger. This allows me to change what areas I want to see output from, with out having to stop and restart the program. This is much, much faster. And it's much faster than stepping and tracing too, which should only be used when you've narrowed a problem down to a very small section of code with the boolean debug variables, and you need a lot of fine detail to find the root cause.
4. Learn about good program design and development.
Get a copy of Kernighan & Pike's "The Practice of Programming" (Addison
I've never heard of this before, I'll have to check it out. Thanks!
M
.
- References:
- Need help with my logic
- From: TechGurl
- Re: Need help with my logic
- From: Lew
- Re: Need help with my logic
- From: TechGurl
- Re: Need help with my logic
- From: Patricia Shanahan
- Re: Need help with my logic
- From: Mark Space
- Re: Need help with my logic
- From: Martin Gregorie
- Need help with my logic
- Prev by Date: Re: java memory leak in cygwin('s Xwin)?
- Next by Date: Quick Servlet question: meaning of getPathInfo()
- Previous by thread: Re: Need help with my logic
- Next by thread: Re: Need help with my logic
- Index(es):
Relevant Pages
|