Debugging Techniques

Get Started. It's Free
or sign up with your email address
Rocket clouds
Debugging Techniques by Mind Map: Debugging Techniques

1. keep your iTerm window

1.1. large

1.1.1. option-command-left arrow with Spectacle

1.2. clean

1.2.1. use Command-R a lot to clear it

2. i.e. it's all inside Rails/gem code

3. Do this when the error message doesn't help

4. explore runtime context

4.1. pry

4.1.1. require 'pry' in your file

4.1.2. use binding.pry anywhere in your file this opens up a console with current context try typing in self to check

4.2. puts or p

4.2.1. why increase your understanding make a hypothesis and confirm or be surprised

4.2.2. how (style, optional) "variable is #{variable}" use puts instead of print for newline use sleeps for infinite loops

4.2.3. where infinite loops once per loop methods very first line runner code is okay inside specs is GREAT

4.2.4. for objects puts object.inspect (or just require 'pp' and pp instead of puts)

5. big picture debugging

5.1. can you revert to a few commits back?

5.2. can another team member get same code to work?

5.2.1. yes check if you're running the same code maybe delete your repo/branch and clone again

6. RTFM: read the (error) message

6.1. read the entire message and try to understand it

6.2. try Googling it

6.3. try command-clicking in iTerm on the line of code where it happened, to open it up in SublimeText

7. follow your code

7.1. What code did you change to cause the error?

7.1.1. Try to reverse it

7.2. Start with the request you make

7.2.1. usually some route gets called by browser/spec

7.3. Then read your code, step-by-step

7.3.1. Controller Any model methods etc.

8. Google/StackOverflow it

8.1. what

8.1.1. specific error message you're getting

8.1.2. thing you're trying to do

8.2. how

8.2.1. read StackOverflow items first

8.2.2. skim, don't read everything

9. solve a smaller problem

9.1. sanity check

9.1.1. when if you're totally confused about what's going on

9.1.2. why feel sane, in control again

9.1.3. what predict something simple check if it's true

9.1.4. examples variable.class == String maybe you're passing the wrong class? editing view change 'Edit' to 'XEdit' esp. for styling issues open localhost in fresh Incognito window

9.2. start a new file, cleaner, less complex

9.2.1. just to increase/confirm your understanding

9.2.2. if it works increase complexity a bit or just consider what's different

9.2.3. if it doesn't find an even simpler problem best idea since you know it

10. look at similar, working code

10.1. you wrote previously

10.1.1. build up a go-to library

10.2. cohort mates wrote

10.2.1. except for assessments obviously

11. learn to explain

11.1. explain your problem to a 'rubber duck'

11.1.1. or camera

11.1.2. or cohort mate

11.2. make yourself think like a dumb computer

11.2.1. go through the code step by step

11.2.2. do exactly what it tells you to do

11.3. try it in real life

11.3.1. especially for iterating through objects

11.3.2. get a bunch of physical objects to mimic your objects

12. just bypass the problem

13. increase your understanding of the topic

13.1. read a tutorial

13.2. read some docs

14. use Rubocop

14.1. add it to your Gemfile

14.2. run rubocop -D filepath

14.2.1. or rubocop -RD for Rails

14.3. especially helpful for mismatched do/end, (, {

15. use specs

15.1. write a spec for each sub-method

15.1.1. or just test something smaller

15.2. def method end

15.2.1. run one at a time

15.2.2. process them in order sometimes troubleshooting a spec is easier than doing it in the console you can print stuff, fresh DB, etc.

15.2.3. usually easiest to hardest

15.3. sometimes troubleshooting in localhost browser is easier than a spec

15.3.1. you can see it, use better_errors gem, etc.