Win a copy of Kotlin Cookbook this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Henry Wong
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Joe Ess
  • salvin francis

Strategy for tracing thru code

 
Greenhorn
Posts: 22
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My studies are going super well thanks to the books that Kathy, Bert, Jeanne and Scott have so generously shared. In doing practice exams I am successful in answering conceptual questions.

But for questions that require tracing thru code and keeping track of the values in variables I panic and become confused. I cant keep track of everything in my head. I dont have a sufficient technique for keeping track of the values in variables on paper. All the youtube examples I've watched for tracing thru code are not relevant because the code is so much simpler than the code I am trying to decipher.

For example in the k&b8 on page 224 question #4 about class Mixer. Or page 225 question 5 about class Fizz.

I spend so much time trying to follow it and then end up guessing. I understand the rules but I get lost trying to keep track of the changing state. I cant take the exam until i become competent tracing code on a piece of paper.

Any advice or links to videos is greatly appreciated.
 
Robin Z. Clark
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On page 228 of k&b8 question #10 about class Network I am in tears thinking maybe I should give up programming and go to school for cosmetology.
 
Saloon Keeper
Posts: 11017
243
  • Likes 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use sticky notes. Each sticky note represents an object. Write the name of each instance field on a separate line on the note.

For fields of a primitive type or String, write the current value next to the field name in pencil. When the value changes, erase it from your sticky note and write the new value down.

For fields of a reference type, draw a line from the field name to another sticky note that represents the object that the field refers to. That's why it's a good idea to put your sticky notes on a larger piece of paper or on a whiteboard. When the reference changes, erase the arrow and draw a new one to the correct sticky note (or none, if the reference is null).

This may take a lot of effort (and paper) at first, but once you become more trained you will be able to find mental mechanisms that work well enough for you for the complexity level that exams use.

Finally, let me reassure you that in real life, you really do not have to keep track of the values of all variables in your head. Instead, you either print out current values when you need to know them, or you use your IDE to show you the current values of all variables as you step through the code line by line. This is what we call debugging (which is more about helping you understand code than it is about finding bugs).
 
Robin Z. Clark
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you. That is exactly the type of idea I was looking for.
 
The fastest and most reliable components of any system are those that are not there. Tiny ad:
Sauce Labs - World's Largest Continuous Testing Cloud for Websites and Mobile Apps
https://coderanch.com/t/722574/Sauce-Labs-World-Largest-Continuous
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!