• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using assert/debugger

 
Preeti Yarla
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I assume it would depend on the standards of the company. What the company uses (does), you use (do).

Justin Fox
 
Paul Clapham
Sheriff
Pie
Posts: 20746
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Paul! Thanks Justin.
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic