Debugging Tips - What is bug and debugging?
Key Takeaways
Introduction to bugs and debugging in computer programming using PyCharm
Full Transcript
hello and welcome to core basics coding tutorial in today's session we are going to learn what is bug and what is debugging first let's see what is bug when it comes to software programming or writing code bug means you wrote a program or a piece of score that doesn't behave the way you expected meaning the program has some kind of fault or error this is called program having a bug for example take a look at this example here you are taking two numbers as an input and you are just doing sum of these two numbers and printing it now this program is written in Python using py charm editor but really the concept applies to any program it could be in C++ Java or any programming language right so if I run this program here it will first ask me to enter two number so I enter two and three and it is saying sum is 23 now if you just look at the program what it is doing is it is adding two numbers n1 n2 and in this function all I am doing is a plus B I am returning that and that's what we are printing here so if you just read the program it everything looks okay so you will wonder what's wrong with this right so this means this program has a bug it doesn't behave the way you expect it to behave so the process of finding bug and fixing it is called debugging debug means debug meaning you are removing bugs from your program this is similar to fixing problem with let's say your car you are driving your car and car has problem and it's not working or it is making some weird sound you will take it to a mechanic and in the garage the mechanic will open the car he will examine different parts and do different tests and he will figure out what is wrong similarly this programming not behaving well so I have to to kind of dig into it analyze the step of execution and watch all the variables and all kind of programming states that are corresponding to that execution and then eventually figure out what's going wrong another real-life example of debugging is called let's say you are sick you go to the doctor and doctor will ask you to do a blood test so they will take your blood sample and the blood sample will go to a laboratory in the laboratory the technician will examine the blood under Microsoft microscope he will do various tests and he will figure out whether you have a sugar level problem or cholesterol problem etc so debugging is similar it's basically using a debugger you are trying to find a problem or within a program that is not behaving well ok so let's examine this program and find out why it is not behaving the way you expect it to behave now right now I am using py charm editor or you can use microsoft visual studio or eclipse whatever editor you're familiar with these are each a circle also called IDE meanings integrated development environment which allows you to write the code as well as debug it ok so here in py charm I will click on this icon you see there is a bug icon here so this means I'm debugging it now before I do bug it um I have set a breakpoint here see normally what happens is if you don't click on this bug and if you directly run the program it will ask you for input and it was straight of executed right so it will just pass through this line and you will not find a chance to examine the state of program carefully so what you want to say program is you want to say ok when you come here at this point so these two things are fine you are just taking input right so I want to I want program to stop here so this means break so this red circle when I click here or when I press f9 in many of the editors f9 is a shortcut for setting a breakpoint breakpoint means when program reaches here it will stop it will not go further so let me click on bug icon here and see what happens okay now here as you can see the program wait a minute yes so the programmed R is asking me to enter first number so 2 and then at ur enter 3 ok I have to use their - concept here like step over and step into meaning go to the next line or go inside the function I want to go inside this add number function and see what's going on so you use this option f11 or step in - when you do that it goes inside the add number function now here one thing you notice is a and B are in course meaning their strings okay also if you go here let me find out the variable ok I'm going to move this back to the down because that's more convenient ok so if you look at the span here here it says variable a and B so this panel is variables panel it shows all the local variables in your function and 2 & 3 are strings actually now when I say next you see s is 23 because what it is doing is it is just adding two strings together right so that's what the problem is the problem is that you are adding two strings instead of adding two numbers so now what you need to do is so I'll so now I know what is the problem the problem is we are not adding two numbers we are adding two strings okay so when you say next nature later spin printing as 23 okay cool so that's why you got the output of 23 here okay so what I need to do is I need to convert these two numbers into integer so when I took it from the console it they were strings when I do N 1 is equal to int and 1 what it is doing is converting a string into integer then n 2 is equal to int n 2 okay so now so let me again set up a breakpoint here and see what happens when I D bug it once I can is asking for the number 2 so when I enter 2 and 1 you can see here it is straight still a string okay until this point N 1 now good thing about pH I'm debugger is in the comment section it will show you the value of that variable when I go to next now see you see that those quotes are gone now so now this became a true number okay now it is asking me for the second number so now second number is also string because there is a quote here when I say next it becomes 3 because of this line okay integer now when I go inside the function a and B as you can see here are integer numbers and when I say next now s is 5 so when I run it now the sum is 5 so now it's behaving the way I expect it to behave so I just found a bug in the code and fixed it ok that was all about what is bug and debugging thank you very much for watch
Original Description
We'll learn what is bug and debugging when it comes to computer programming. Bug is nothing but a defect in code whereas debugging is a process of finding this defect. Let's learn more about it in this tutorial. I am using pycharm community edition IDE for this tutorial.
Topics that are covered in this Video:
0:00 What is bug?
0:30 Example of the bug.
1:28 What is debugging?
2:30 Live example of debugging.
Do you want to learn technology from me? Check https://codebasics.io/ for my affordable video courses.
Next video:
Debugging Tips - Conditional Breakpoint: https://www.youtube.com/watch?v=Tjkz4Kt21wI&list=PLeo1K3hjS3uu-0i4uha0_lZwh5PpIWB1T&index=2
Website: https://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 · 39 of 60
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
▶
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Python Tutorial - 1. Install python on windows
codebasics
Python Tutorial - 2. Variables
codebasics
Python Tutorial - 3. Numbers
codebasics
Python Tutorial - 4. Strings
codebasics
Python Tutorial - 5. Lists
codebasics
Python Tutorial - 6. Install PyCharm on Windows
codebasics
PyCharm Tutorial - 7. Debug python code using PyCharm
codebasics
Python Tutorial - 8. If Statement
codebasics
Python Tutorial - 9. For loop
codebasics
Python Tutorial - 10. Functions
codebasics
Python Tutorial - 11. Dictionaries and Tuples
codebasics
Python Tutorial - 12. Modules
codebasics
Python Tutorial - 13. Reading/Writing Files
codebasics
How to install Julia on Windows
codebasics
Python Tutorial - 14. Working With JSON
codebasics
Julia Tutorial - 1. Variables
codebasics
Julia Tutorial - 2. Numbers
codebasics
Python Tutorial - 15. if __name__ == "__main__"
codebasics
Julia Tutorial - Why Should I Learn Julia Programming Language
codebasics
Python Tutorial - 16. Exception Handling
codebasics
Julia Tutorial - 3. Complex and Rational Numbers
codebasics
Julia Tutorial - 4. Strings
codebasics
Python Tutorial - 17. Class and Objects
codebasics
Julia Tutorial - 5. Functions
codebasics
Julia Tutorial - 6. If Statement and Ternary Operator
codebasics
Julia Tutorial - 7. For While Loop
codebasics
Python Tutorial - 18. Inheritance
codebasics
Julia Tutorial - 8. begin and (;) Compound Expressions
codebasics
Python Tutorial - 12.1 - Install Python Module (using pip)
codebasics
Julia Tutorial - 9. Tasks (a.k.a. Generators or Coroutines)
codebasics
Julia Tutorial - 10. Exception Handling
codebasics
Python Tutorial - 19. Multiple Inheritance
codebasics
Python Tutorial - 20. Raise Exception And Finally
codebasics
Python Tutorial - 21. Iterators
codebasics
Python Tutorial - 22. Generators
codebasics
Python Tutorial - 23. List Set Dict Comprehensions
codebasics
Python Tutorial - 24. Sets and Frozen Sets
codebasics
Python Tutorial - 25. Command line argument processing using argparse
codebasics
Debugging Tips - What is bug and debugging?
codebasics
Debugging Tips - Conditional Breakpoint
codebasics
Debugging Tips - Watches and Call Stack
codebasics
Python Tutorial - 26. Multithreading - Introduction
codebasics
Git Tutorial 3: How To Install Git
codebasics
Git Tutorial 1: What is git / What is version control system?
codebasics
Git Tutorial 2 : What is Github? | github tutorial
codebasics
Git Tutorial 4: Basic Commands: add, commit, push
codebasics
Git Tutorial 5: Undoing/Reverting/Resetting code changes
codebasics
Git Tutorial 6: Branches (Create, Merge, Delete a branch)
codebasics
Git Github Tutorial 10: What is Pull Request?
codebasics
Git Tutorial 7: What is HEAD?
codebasics
Git Tutorial 9: Diff and Merge using meld
codebasics
Difference between Multiprocessing and Multithreading
codebasics
Python Tutorial - 27. Multiprocessing Introduction
codebasics
Python Tutorial - 28. Sharing Data Between Processes Using Array and Value
codebasics
Git Tutorial 8 - .gitignore file
codebasics
Python Tutorial - 29. Sharing Data Between Processes Using Multiprocessing Queue
codebasics
Python Tutorial - 30. Multiprocessing Lock
codebasics
Python Tutorial - 31. Multiprocessing Pool (Map Reduce)
codebasics
What is code?
codebasics
Python unit testing - pytest introduction
codebasics
Related AI Lessons
Chapters (4)
What is bug?
0:30
Example of the bug.
1:28
What is debugging?
2:30
Live example of debugging.
🎓
Tutor Explanation
DeepCamp AI