This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Using assert/debugger Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Using assert/debugger" Watch "Using assert/debugger" New topic
Author

Using assert/debugger

Preeti Yarla
Ranch Hand

Joined: Sep 08, 2007
Posts: 69
In all of my code (amateur learner code) I never used assert, because I was thinking that I don't need an assert when I am using a debugger. But in the industry does your boss expect you to use assert even if we have a debugger? (OR no one cares as long as you can debug?)

Thanks.


SCJP
Justin Fox
Ranch Hand

Joined: Jan 24, 2006
Posts: 802
I assume it would depend on the standards of the company. What the company uses (does), you use (do).

Justin Fox


You down with OOP? Yeah you know me!
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Assertions and debugging are tools which are used for different purposes. Approximately speaking, assertions are used to ensure that code is doing what it is supposed to do. One normally assumes (hopes) that assertions will not be triggered, except during the testing phase. In that way they are a support tool for testing.

But debugging is used to find out why a program is not doing what you think it should be doing. Debugging only helps you to find out what happened on one particular run of your code. You aren't going to debug every single line of your code for every single test case and verify on a checklist that the right thing is happening.

So don't be surprised if you find both assertions and debugging being used.
Preeti Yarla
Ranch Hand

Joined: Sep 08, 2007
Posts: 69
Thanks Paul! Thanks Justin.
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
Originally posted by Paul Clapham:
But debugging is used to find out why a program is not doing what you think it should be doing.


This certainly is a common use for the debugger, but is not the only one.

It is often productive to use the debugger to step through your new code, even when you do not have a specific bug to find. By doing so, you verify that variables really do have the values you think they should, and that the path through the code is what you expect.

You can't do this for every piece of code, but when you have written something short, but complicated, it can be invaluable.


Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
 
 
subject: Using assert/debugger
 
Similar Threads
JUnit : AssertionFailed on String Comparison
Assert syntax
[Bodgit Scrapper] what's the meaning of magic cookie value?
NX:Create/Delete invalid data
junit.framework.Assert Class?????