Git Product home page Git Product logo

debugging's Introduction

Debugging

In this workshop, you will practice translating programming skills learned in EdX to a professional setting. You will learn how to use VSCode’s debugger to step through code, and how to build your debugging instincts when working on larger programs.

Debugging is a complicated skill. It's a mix of experience ("I've seen this before ..."), strategies ("I'll try back-tracing this time"), specific knowledge ("This pandas method modifies the data in-place"), patience ("Breath in, breath out, try again") and good habits ("If only I'd written tests!"). You will never know everything about debugging because every project is different. But if you practice good habits, you will be ready to fix new bugs when you find them.

debugging tactics


Learning Objectives

Priorities: πŸ₯šπŸ£πŸ₯πŸ” (click for more info)

Learning objective for this workshop are labeled so you can prioritize your study time. The emojis show the minimum mastery you are expected to achieve for each skill, but there is no maximum! If you have the time you should aim to master all of the skills introduced in this workshop.

  • πŸ₯š You are expected to master these skills. They are the foundations you will need to move forward.
  • 🐣 You are expected to be comfortable with these skills. It's ok if you still need help sometimes.
  • πŸ₯ You are expected to be familiar with these skills. It's enough to recognize them in practice and apply them with help.
  • πŸ” You are not expected to know these skills, but they are important if you want to excel. You should only focus on these after mastering the πŸ₯š, 🐣 and πŸ₯ objectives.

VSCode

  • πŸ₯š You can open a folder in VSCode and browse it's contents in the Explorer pane.
  • πŸ₯š You can open a terminal in VSCode and run a Python script.
  • πŸ₯š You can create, rename and delete files and folders in the Explorer pane.

VSCode Debugger

  • πŸ₯š Using Breakpoints:
    • You can add and remove breakpoints, before and while you are debugging a program.
    • You can enable and disable breakpoints without removing them.
  • πŸ₯š Launching the Debugger: You can open the debugger pane and launch a single-file Python program.
  • Debugger Buttons
    • πŸ₯š Skip Ahead: You can skip ahead to the next breakpoint or the end of the program.
    • πŸ₯š Step Over: You can step over a function call to ignore its implementation.
    • πŸ₯š Step In: You can step into a function call to debug it's implementation.
    • πŸ₯š Step Out: You can step out of a function call to resume debugging the main program.
    • πŸ₯š Restart: You can restart your debugger at the beginning of the program.
    • πŸ₯š Exiting: You can exit the debugger at any point of execution.
  • πŸ₯š Reading State: At each point in a program's execution, you can find the value of any declared variable in the Variables pane.
  • The Call Stack:
    • πŸ₯š You understand the relationship to between the callstack pane, local variables and function calls.
    • πŸ₯š You can view the local variables for each level of the callstack by clicking on it.
  • 🐣 Tracing Recursion: You can debug a recursive algorithm by tracing through it's callstack in the debugger.
  • 🐣 Variable Categories: You can explain the difference between Locals, Globals, Function Variables, Class Variables, and Special Variables
  • πŸ₯ Watch Expressions: You can create helpful watch expressions and use them to track information about your program that is not explicitly declared in the code.

Debugging Mindset & Strategies

  • πŸ¦† You are not embarrassed to do some rubber duck debugging.
  • πŸ₯š You know that someone else will always use your program in a way you didn't imagine.
  • πŸ₯š You can study a program skeptically, always asking "how can I break this program?".
  • πŸ₯š Pair programming with someone you trust.
  • 🐣 You can predict a program's behavior while stepping through in the debugger:
    • Which line will execute next?
    • What will change in memory (callstack and variables)?
  • 🐣 You can identify steps of execution that surprise you. This will help understand the gap between what a program does do, and what it should do.
  • 🐣 You can recognize these four types of bug: overt vs. covert, and persistent vs. intermittent.
  • 🐣 You can clearly describe a bug by answering these questions:
    • what should the program do? Name specific test cases and lines of code!
    • What does the program do? Name specific test cases and lines of code!
  • πŸ₯ You can trace a program backwards from a surprising step to understand how it happened (either mentally or on paper, VSCode's debugger only goes forward).

Avoiding Bugs in the Fist Place

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.

  • πŸ₯š Pair programming with someone you trust.
  • πŸ₯š Always use the simplest and most understandable solution. (KISS)
  • πŸ₯š Develop your code one small step at a time, writing and running tests for each change before moving on.
  • πŸ₯š Have others read and review your code, they will find mistakes you missed and think of improvements you wouldn't.
  • πŸ₯š Write less code. Keep your end goal in mind and avoid writing any code that is not absolutely necessary to reach your goal.
  • πŸ₯š Keep a Bug Log; Write down bugs you've encountered and how you fixed them. This log will help you avoid making the same mistakes, and double as inspiration for how to fix new bugs.

Prep Work

How to prepare before the workshop:

If you have more time, you can watch the /1_stepping_through guide video and practice with the /0_stepping_through exercises.


Workshop Outline

Workshop Overview (all together)

The workshop instructor will introduce the main concepts of this workshop:

Practice Predictive Stepping (small groups)

Have one person in your group share their screen, then practice asking and answering these questions as you study the programs in /0_stepping_through:

Before each step:

  • Which line will run next?
  • What will change in memory? (variables and callstack!)

After each step:

  • Were your predictions correct?
  • If now, why? What did you miss when you made your prediction?

The Debugging Mindset (all together)

  • Each group will have 1 minute to share:
    • One thing they couldn't understand
    • One interesting thing they learned
  • Introduce the next exercises

Find the Bugs! (small groups)

Try to find the bug in each program of /1_find_the_bugs:

Discussion & Introduce Next Exercise (all together)

  • Each group will have 1-2 minutes to share:
    • One thing they couldn't figure out
    • One surprising thing they learned
    • One thing they'd like to discuss with the full class
  • Discuss how you approach code differently when you expect it has a bug, and why it's important to always think this way.
  • Introduce the next exercises.

Fix the Bugs! (small groups)

Find and fix as many bugs as you can in /2_fix_the_bugs!

Discussion (all together)

  • Each group will have 2-3 minutes to share:
    • One thing they couldn't figure out
    • One surprising thing they learned
    • One thing they'd like to discuss with the full class
  • Discuss!

debugging's People

Contributors

colevanderswands avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.