Debugging
Last updated
Was this helpful?
Last updated
Was this helpful?
Debugging is the process of tracking down and correcting erros in code. The erors are called bugs.
Three kinds of errors can occur in a program:
Syntax refers to the structure of a program and the rules about that structure. AKA GRAMMAR.
Python does not run if there is a single error. Unlike JavaScript, HTML and CSS rendering in the browsers.
Found by compiler/interpreter on the fly.
The error does not appear until the program run. These errors are also called exceptions because they usually indicate that something exceptional (and bad) has happened.
E.g dividing by zero is a runtime error. Python will not see it with 100% because it could be an input from user. It is forbidden as of rules, but it will appear during runtime.
The problem is that the program you wrote is not the program you wanted to write. It is an error that makes your program do the wrong thing, even if the code syntax is 100% fine.
For some people, programming and debugging are the same thing. That is, programming is the process of gradually debugging a program until it does what you want.
Start with something, and than make it better. Small steps approach.
start small
break things down
debug
get happy
move to the next small thing
start small (again)
keep it working
Get something working and keep it working
test things as you go
think of boundary conditions
Debugging tips:
read error messages, no really do!
use print statements
Our brain tends to see what we think is there.
ParseError - error in the syntax
TypeError - try to combine two objects that are not compatible or you tried to do something that a type of data can't do
NameError - typo of any kind, in variable, in function, etc, use sth not there
ValueError - wrong value to work with, for example: int("")
URIError
TokenError
SyntaxError - if you write invalid syntax, bad code, e.g. EOL for string errors
TimeLimitError
IndentationError
AttributeError
ImportError
IndexError