Debugging Tips - Watches and Call Stack

codebasics · Beginner ·📐 ML Fundamentals ·10y ago

Key Takeaways

Provides debugging tips using Watches and Call Stack in PyCharm with Python code

Full Transcript

hello friends welcome to core basics coding tutorial and today's debugging tip we are going to talk about watches and call stack I would suggest that you watch my video on what is debugging if you haven't already done so so after that you can continue and watch this tutorial alright now here I have a simple Python program where I have a list of numbers and I have returned a for loop to go or all these numbers and do their sum so in the end I'm printing the total of these numbers pretty simple and straightforward program okay now when I divide this using this bug icon okay I want to set a breakpoint here and I want to kind of understand how this for loop works and at each iteration what happens okay so I use this bug icon to debug it and when I do it py charm will by default open few windows so here I have first window which is frames window the second one is variables and the third one is watches okay now let me when you get this window for the first time it will look like this it will be blank okay now before we talk about watches window let's talk about variables what variable window shows you is all the local variables so here we have numbers total num all these variables it will show here other than that it will show you some system defined built-in functions underscore underscore file etc okay so what what is does is similar to variable window but it allows you to watch a specific variable okay so let me add num here so when I add num it will show me the current value of number okay and then let me add another watch called total so here you have a breakpoint at this point and you are just adding a bunch of keywords that a bunch of variables that you are watching okay now when you say next you will see here that the values are changing so you can monitor the progress of your program by having this watch window now you get the same thing in variable window as well you can see here also the number is changing so these two are essentially same but good thing about watch window is that you can only watch the things that you are interested in versus in variable and it will show you all all the variables basically so there'll be too much noise here on my program is pretty simple in real life your program will be much complex and you will have so many variables here that it becomes hard to watch what you are interested in that's why I personally love this watch window you can just plus minus you can remove these things at any time okay you can also add the expression so for example I want to know what are the built-in functions for num and when I do that it will show me all the building functions for numbers okay so you can add variables you can an expression etc so that was all about watches window next thing we are going to cover is the call stack so kostik is this guy here okay now in this program it's not quite clear so let me just modify it so let's see I have this function called foo which caused another cup function called bar and there is a function called bar which will do nothing and here in my main program I will call function foo okay now the way calling function works is there is a memory area called stack so when I execute this program what will happen is first it will stop here then when I step into it it goes into bar then when I again step into it this is step into or f11 sort keyboard keyboard shortcut then it okay goes into bar function so I was in info from foo call bar and then I now I'm in bar okay now let's say you are debugging a complex program and you are here and sometimes you know you might have a very complex call stack you might be coming from 10 different function in that case this pan call call stack is pretty useful here it will show you the whole stack of your call so it says okay first when you double click on it it will say ok it foo was called then foo call bar and then you are here so call stack shows you where you are at present and it also shows you from where you are coming at ok so again when you are debugging a complex program call stack is extremely useful if the the call stack is called frames in phm code editor but there are other editors such as Microsoft Visual Studio and Eclipse where it is called all stack again this these concepts variables watches call stack frames they are all common concepts they are not specific to py term code editor these concepts apply to other famous code editors as well so once you know these concepts you can pretty much use it with any programming language with any editor ok that is all about watches and call stack thank you for watching

Original Description

I'll show you what is watch and call stack in terms of code debugging. Using sample python code and pycharm code editor I will explain these concepts but remember that the concepts remain same no matter what programming language or code editor you are using. Topics that are covered in this Video: 0:00 Introduction 0:58 What is Watches window? 3:41 What is Call Stack? Do you want to learn technology from me? Check https://codebasics.io/ for my affordable video courses. Website: http://codebasics.io/ Facebook: https://www.facebook.com/codebasicshub Twitter: https://twitter.com/codebasicshub
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from codebasics · codebasics · 41 of 60

1 Python Tutorial - 1. Install python on windows
Python Tutorial - 1. Install python on windows
codebasics
2 Python Tutorial - 2. Variables
Python Tutorial - 2. Variables
codebasics
3 Python Tutorial - 3. Numbers
Python Tutorial - 3. Numbers
codebasics
4 Python Tutorial - 4. Strings
Python Tutorial - 4. Strings
codebasics
5 Python Tutorial - 5. Lists
Python Tutorial - 5. Lists
codebasics
6 Python Tutorial - 6. Install PyCharm on Windows
Python Tutorial - 6. Install PyCharm on Windows
codebasics
7 PyCharm Tutorial - 7. Debug python code using PyCharm
PyCharm Tutorial - 7. Debug python code using PyCharm
codebasics
8 Python Tutorial -  8. If Statement
Python Tutorial - 8. If Statement
codebasics
9 Python Tutorial - 9. For loop
Python Tutorial - 9. For loop
codebasics
10 Python Tutorial -  10. Functions
Python Tutorial - 10. Functions
codebasics
11 Python Tutorial - 11. Dictionaries and Tuples
Python Tutorial - 11. Dictionaries and Tuples
codebasics
12 Python Tutorial - 12. Modules
Python Tutorial - 12. Modules
codebasics
13 Python Tutorial - 13. Reading/Writing Files
Python Tutorial - 13. Reading/Writing Files
codebasics
14 How to install Julia on Windows
How to install Julia on Windows
codebasics
15 Python Tutorial - 14. Working With JSON
Python Tutorial - 14. Working With JSON
codebasics
16 Julia Tutorial - 1. Variables
Julia Tutorial - 1. Variables
codebasics
17 Julia Tutorial - 2. Numbers
Julia Tutorial - 2. Numbers
codebasics
18 Python Tutorial - 15. if __name__ == "__main__"
Python Tutorial - 15. if __name__ == "__main__"
codebasics
19 Julia Tutorial - Why Should I Learn Julia Programming Language
Julia Tutorial - Why Should I Learn Julia Programming Language
codebasics
20 Python Tutorial  - 16. Exception Handling
Python Tutorial - 16. Exception Handling
codebasics
21 Julia Tutorial - 3. Complex and Rational Numbers
Julia Tutorial - 3. Complex and Rational Numbers
codebasics
22 Julia Tutorial - 4. Strings
Julia Tutorial - 4. Strings
codebasics
23 Python Tutorial -  17. Class and Objects
Python Tutorial - 17. Class and Objects
codebasics
24 Julia Tutorial - 5. Functions
Julia Tutorial - 5. Functions
codebasics
25 Julia Tutorial - 6. If Statement and Ternary Operator
Julia Tutorial - 6. If Statement and Ternary Operator
codebasics
26 Julia Tutorial - 7. For While Loop
Julia Tutorial - 7. For While Loop
codebasics
27 Python Tutorial  - 18. Inheritance
Python Tutorial - 18. Inheritance
codebasics
28 Julia Tutorial - 8. begin and (;) Compound Expressions
Julia Tutorial - 8. begin and (;) Compound Expressions
codebasics
29 Python Tutorial - 12.1 - Install Python Module (using pip)
Python Tutorial - 12.1 - Install Python Module (using pip)
codebasics
30 Julia Tutorial - 9. Tasks (a.k.a. Generators or Coroutines)
Julia Tutorial - 9. Tasks (a.k.a. Generators or Coroutines)
codebasics
31 Julia Tutorial - 10. Exception Handling
Julia Tutorial - 10. Exception Handling
codebasics
32 Python Tutorial  - 19. Multiple Inheritance
Python Tutorial - 19. Multiple Inheritance
codebasics
33 Python Tutorial - 20. Raise Exception And Finally
Python Tutorial - 20. Raise Exception And Finally
codebasics
34 Python Tutorial - 21. Iterators
Python Tutorial - 21. Iterators
codebasics
35 Python Tutorial - 22. Generators
Python Tutorial - 22. Generators
codebasics
36 Python Tutorial - 23. List Set Dict Comprehensions
Python Tutorial - 23. List Set Dict Comprehensions
codebasics
37 Python Tutorial - 24. Sets and Frozen Sets
Python Tutorial - 24. Sets and Frozen Sets
codebasics
38 Python Tutorial - 25. Command line argument processing using argparse
Python Tutorial - 25. Command line argument processing using argparse
codebasics
39 Debugging Tips - What is bug and debugging?
Debugging Tips - What is bug and debugging?
codebasics
40 Debugging Tips - Conditional Breakpoint
Debugging Tips - Conditional Breakpoint
codebasics
Debugging Tips - Watches and Call Stack
Debugging Tips - Watches and Call Stack
codebasics
42 Python Tutorial - 26. Multithreading - Introduction
Python Tutorial - 26. Multithreading - Introduction
codebasics
43 Git Tutorial 3:  How To Install Git
Git Tutorial 3: How To Install Git
codebasics
44 Git Tutorial 1: What is git / What is version control system?
Git Tutorial 1: What is git / What is version control system?
codebasics
45 Git Tutorial 2 : What is Github? | github tutorial
Git Tutorial 2 : What is Github? | github tutorial
codebasics
46 Git Tutorial 4: Basic Commands: add, commit, push
Git Tutorial 4: Basic Commands: add, commit, push
codebasics
47 Git Tutorial 5: Undoing/Reverting/Resetting code changes
Git Tutorial 5: Undoing/Reverting/Resetting code changes
codebasics
48 Git Tutorial 6: Branches (Create, Merge, Delete a branch)
Git Tutorial 6: Branches (Create, Merge, Delete a branch)
codebasics
49 Git Github Tutorial 10: What is Pull Request?
Git Github Tutorial 10: What is Pull Request?
codebasics
50 Git Tutorial 7: What is HEAD?
Git Tutorial 7: What is HEAD?
codebasics
51 Git Tutorial 9: Diff and Merge using meld
Git Tutorial 9: Diff and Merge using meld
codebasics
52 Difference between Multiprocessing and Multithreading
Difference between Multiprocessing and Multithreading
codebasics
53 Python Tutorial - 27. Multiprocessing Introduction
Python Tutorial - 27. Multiprocessing Introduction
codebasics
54 Python Tutorial - 28. Sharing Data Between Processes Using Array and Value
Python Tutorial - 28. Sharing Data Between Processes Using Array and Value
codebasics
55 Git Tutorial 8 - .gitignore file
Git Tutorial 8 - .gitignore file
codebasics
56 Python Tutorial - 29. Sharing Data Between Processes Using Multiprocessing Queue
Python Tutorial - 29. Sharing Data Between Processes Using Multiprocessing Queue
codebasics
57 Python Tutorial - 30. Multiprocessing Lock
Python Tutorial - 30. Multiprocessing Lock
codebasics
58 Python Tutorial - 31. Multiprocessing Pool (Map Reduce)
Python Tutorial - 31. Multiprocessing Pool (Map Reduce)
codebasics
59 What is code?
What is code?
codebasics
60 Python unit testing - pytest introduction
Python unit testing - pytest introduction
codebasics

Related AI Lessons

Stop Overfitting With Basically One Line of Code
Learn to prevent overfitting with a simple code tweak and understand the difference between Ridge and Lasso regression
Medium · AI
Stop Overfitting With Basically One Line of Code
Learn to prevent overfitting in machine learning models with a simple code tweak and understand the difference between Ridge and Lasso regression
Medium · Machine Learning
Stop Overfitting With Basically One Line of Code
Prevent overfitting in models with a simple code tweak, understanding the difference between Ridge and Lasso regression
Medium · Data Science
Stop Overfitting With Basically One Line of Code
Learn to prevent overfitting in machine learning models with a simple code tweak, comparing Ridge and Lasso regression techniques
Medium · Python

Chapters (3)

Introduction
0:58 What is Watches window?
3:41 What is Call Stack?
Up next
Learn Deep Learning by Hand (Beginner's Guide - Part 1)
Thu Vu
Watch →