Presentation is loading. Please wait.

Presentation is loading. Please wait.

Problem of the Day  Why are manhole covers round?

Similar presentations


Presentation on theme: "Problem of the Day  Why are manhole covers round?"— Presentation transcript:

1 Problem of the Day  Why are manhole covers round?

2

3 Announcements  If you need more review of Java…  I have lots of good resources – talk to me  Use “Additional Help” link on webpage  Weekly assignments problems due before class  Remove rust from summer and get back into coding  Starting this lecture will be adding new material, too

4 Ever Have A Bug?  At some point, everyone must fix bug in code  What should you do first after discovering the bug?

5 Ever Have A Bug?  At some point, everyone must fix bug in code  What should you do first after discovering the bug?

6 Ever Have A Bug?  At some point, everyone must fix bug in code  What should you do first after discovering the bug?

7 Ever Have A Bug?  At some point, everyone must fix bug in code  What should you do first after discovering the bug?

8 Ever Have A Bug?  At some point, everyone must fix bug in code  What should you do first second after discovering it?

9 Fixing Bugs  Three common ways students fix bugs:  Guess where error is and make random change  Use Eclipse debugger to run program & find source  Get out your pencil & paper and draw a memory trace

10 Normal Method of Debugging  Also called "debugging-via-drunken-walk" SMALL  Can work for SMALL programs with limited choices  Guessing for millions of lines of code harder  Not at all effective at actually fixing errors  Entire point is to avoid understanding bug's cause  "Fix" may cause other errors later on in program  Cannot prevent future errors using this approach

11 Better Method of Debugging  Could use Eclipse debugger to find and fix bug  Set breakpoints to stop program where bug likely  Use step filters to walk through the program bit by bit  Spend a few hours learning how to make it work  Can get to root of problem once it is executed  But requires executing entire program to trigger bug  Cannot work backward to try and understand why

12 Best Method of Debugging  Generating memory trace has many benefits  Could check algorithm – don’t need any code to try  Can make up situations and just trace a method  Look back through trace to see root cause of bug  Trace code by running it like you were computer  DON’T SKIP STEPS  DON’T SKIP STEPS – easy to (wrongly) assume things  As you go along update variables’ values  GIGO effects limit tracing’s effectiveness

13 Best Method of Debugging  Generating memory trace has many benefits  Could check algorithm – don’t need any code to try  Can make up situations and just trace a method  Look back through trace to see root cause of bug  Trace code by running it like you were computer  DON’T SKIP STEPS  DON’T SKIP STEPS – easy to (wrongly) assume things  As you go along update variables’ values  GIGO effects limit tracing’s effectiveness

14 Benefits of Memory Traces  Draw what actually occurs in memory  Pictures used to debug rather than bare text  Much easier to understand what a method does  Excellent way to learn new programming topics  Past studies found improves student grades  Debugging time decreased greatly at same time  Greater support for these traces in Eclipse  Drawing of static trace integrated with debugger  Over this term should see tools improve

15 Starting a Memory Trace  Paper will hold 2 areas separated by vertical line  Program stack drawn on left part of page  Right side of page holds the program heap  Objects allocated during run drawn in the heap  Will discuss how this is done next week  Draw frame on top of stack each method call  Fancy name for box labeled with method name  Each parameter & local variable needs space in box

16 Starting a Memory Trace public static void main(String[] args) { String s = “”; for (int i = 0; i < 5; i+=2) { s = s + i; } }

17 Writing a Memory Trace public static String getName(int i) { return “Bob the ” + i + “th”; }

18 Writing a Memory Trace public static String getName(int i) { return “Bob the ” + i + “th”; } public static void main(String[] args) { String s = “”; String oldS; for (int i = 0; i < 5; i+=4) { oldS = s; s = getName(i); } }

19 Your Turn  Get into your groups and complete activity

20 For Next Lecture  Reading AF Chapter 3 & 7.13 for Monday  Continues Java review & looks at references  Introduces enum s – first really new concept of term  Use language template to take notes on enum s!  There is weekly assignment problem on Angel  Due before Monday’s lecture (via e-mail)  Get back into the swing of writing Java code


Download ppt "Problem of the Day  Why are manhole covers round?"

Similar presentations


Ads by Google