Presentation is loading. Please wait.

Presentation is loading. Please wait.

Topics: jGRASP editor ideosyncrasies assert debugger.

Similar presentations


Presentation on theme: "Topics: jGRASP editor ideosyncrasies assert debugger."— 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

5 before after 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).

6 assert

7 assert (from http://java. sun
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.

8 assert (from http://java. sun
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.

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

10 assert (from http://java. sun
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.

11 assert (from http://java. sun
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

12 assert (from http://java. sun
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.

13 assert (from http://java. sun
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.

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

15 When disabled (default) . . .

16 When enabled . . .

17 The debugger

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

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

20 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!

21 Setting a breakpoint

22 Breakpoint is now set

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

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


Download ppt "Topics: jGRASP editor ideosyncrasies assert debugger."

Similar presentations


Ads by Google