1 / 24

Topics:

Topics:. jGRASP editor ideosyncrasies assert debugger. jGRASP editor-syncrasies (idiosyncrasies). The jGRASP editor. Problem: Indentation seems to befuddle the jGRASP editor. Solution: Tell jGRASP to use spaces instead of tabs. after. before.

dana
Download Presentation

Topics:

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Topics: • jGRASP editor ideosyncrasies • assert • debugger

  2. jGRASP editor-syncrasies(idiosyncrasies)

  3. The jGRASP editor • Problem: Indentation seems to befuddle the jGRASP editor. • Solution: Tell jGRASP to use spaces instead of tabs.

  4. after before Check Soft Tabs and set the Tab Size to 4. Click Apply and then OK. Now pressing the tab key will insert 4 spaces (and existing tabs will be converted to 4 space).

  5. assert

  6. assert (from http://java.sun.com/developer/technicalArticles/JavaLP/assertions/) • An assertion has a Boolean expression that, if evaluated as false, indicates a bug in the code. • This mechanism provides a way to detect when a program starts falling into an inconsistent state. • Assertions are excellent for documenting assumptions and invariants about a class.

  7. assert (from http://java.sun.com/developer/technicalArticles/JavaLP/assertions/) • Here is a simple example of assertion: BankAccount acct = null; // ... // Get a BankAccount object // ... // Check to ensure we have one assert acct != null; • This asserts that acct is not null. If acct is null, an AssertionError is thrown. Any line that executes after the assert statement can safely assume that acct is not null.

  8. assert • Part of C/C++ through assert.h since the dawn of time. • Officially added to Java 1.4 (and newer).

  9. assert (from http://java.sun.com/developer/technicalArticles/JavaLP/assertions/) • Design by Contract • We can view program correctness as proof that the computation, given correct input, terminated with correct output. The user invoking the computation has the responsibility of providing the correct input, which is a precondition. If the computation is successful, we say that the computation has satisfied the postcondition.

  10. assert (from http://java.sun.com/developer/technicalArticles/JavaLP/assertions/) • Design by Contract • Some programming languages (such as Eiffel) encourage developers to provide formal proof of correctness by writing assertions that may appear in the following roles: • precondition • postcondition • invariant

  11. assert (from http://java.sun.com/developer/technicalArticles/JavaLP/assertions/) • Design by Contract (formal) • precondition • A condition that the caller of an operation agrees to satisfy. • postcondition • A condition that the method itself promises to achieve. • invariant • A condition that a class must satisfy anytime a client could invoke an object's method, or a condition that should always be true for a specified segment or at a specified point of a program.

  12. assert (from http://java.sun.com/developer/technicalArticles/JavaLP/assertions/) • Design by Contract (informal) • precondition What does it expect? • postcondition What does it guarantee? • invariant What does it maintain? • These three roles collectively support what is called the design-by-contract model of programming.

  13. Asserts must first be enabled.In jGRASP . . . (or File) Note: Must be FLAGS2 – not FLAGS!

  14. When disabled (default) . . .

  15. When enabled . . .

  16. The debugger

  17. Using the debugger • A primitive way of debugging is to insert print statements.

  18. Using the debugger • A primitive way of debugging is to insert print statements. • That’s OK but a debugger is much more powerful.

  19. Using the debugger • A primitive way of debugging is to insert print statements. • That’s OK but a debugger is much more powerful. • It allows us to execute our code one line at a time. • It allows us to set breakpoints (stop points) in our code. • We can even examine (and even change) the contents of variables as our program runs!

  20. Setting a breakpoint

  21. Breakpoint is now set

  22. Start the debugger • Build -> Debug • The program then runs and stops at our first breakpoint.

  23. step over step in step out variables (r-click to change value) next line to be executed end debugging

More Related