Slide 1

Slide 1 text

Installation instructions 1. Install an IDE, for example: ● PyCharm (https://www.jetbrains.com/help/pycharm/installation-guide.html) ● VS Code (https://code.visualstudio.com/docs/setup/setup-overview) + Python support 2. Clone the repository at https://github.com/stecklin/debugging-workshop >>> git clone https://github.com/stecklin/debugging-workshop.git 3. Install the requirements (pandas, scikit-learn) Go into repository directory and run >>> pip install -r requirements.txt or >>> conda install --yes --file requirements.txt

Slide 2

Slide 2 text

Debug like a pro Marianne Stecklina @MStecklina

Slide 3

Slide 3 text

What is the debugger? A tool to step through code line by line. The debugger can help you to ● Find bugs FAST ● Understand (other people's) code ● Develop new code

Slide 4

Slide 4 text

How I came to do this workshop...

Slide 5

Slide 5 text

Which IDE do you use? 1) PyCharm 2) VS Code 3) Other

Slide 6

Slide 6 text

How often do you use the debugger? 1) Regularly (= every week) 2) Seldom (= only for difficult bugs) 3) Never (= don’t like it / don’t know how)

Slide 7

Slide 7 text

How this workshop works ● Structured into 5 exercises ● Starting point is always main.py For each exercise: ● I’ll explain the theory ● Instructions and screenshots for PyCharm and VS Code ● 10 - 15 minutes for you to try it out ● Follow the “TODO” comments in the code

Slide 8

Slide 8 text

Exercise 0: Creating a debugger config ● Run > Edit configurations… ● Add new configuration (+) ● Select script path ● (Add parameters) ● Run / Debug > Open configurations ● Use “Python: Current File” config or add new Python config ● New config: Type name and program ● (Add args)

Slide 9

Slide 9 text

Exercise 0: Creating a debugger config ● Click next to line number to set a breakpoint in main.py ● Select config and click Debug ● Click next to line number to set a breakpoint in main.py ● Select config and click Start Debugging

Slide 10

Slide 10 text

Exercise 1: Navigation F9 Resume program / Continue Execute code until next breakpoint F5 F8 Step over Execute one line in the current file F10 F7 Step into Step into the function that is called in the current line F11 Shift + F8 Step out Execute code until the end of the current function, and step out to where function was called Shift + F11

Slide 11

Slide 11 text

Exercise 2: Conditional breakpoints ● Create a normal breakpoint ● Right click on breakpoint ● Insert condition ● Create a normal breakpoint ● Right click on breakpoint > Edit Breakpoint… ● Insert condition

Slide 12

Slide 12 text

Exercise 3: Variables and watches ● Select a function from Frames / CallStack ● Check variables ● Add watches

Slide 13

Slide 13 text

Exercise 4: Evaluate expressions ● Click evaluate expression (Alt + F8) ● Type a command ● Open the tab Debug Console ● Type a command

Slide 14

Slide 14 text

Thanks and keep practicing!