What can you do to achieve high quality programming?
What is defensive programming?
What can you do to test your programs?
i. e. it’s not working
What is debugging?
Study the events leading up to an error
How can you create a good debugging experience?
When are you ready to test?
What testing classes do we know?
What testing approaches do we know?
What is blackbox testing?
What is glassbox testing?
disadvantages:
- missing paths
- can go through loops randomly many times
Can a pass complete test miss a bug?
yes, test boundary cases
What are print statements good for?
To test hypothesis
use bisection method:
-> put print halfway in code
What are the steps in debugging?
When do you get an index error?
I.e. trying to access beyond the limits of a list
When do you get an TypeError?
2. Mixing data types without appropriate coercion
When do you get a NameError?
When you reference a non-existent variable
When do you get a syntax error?
python can’t parse the program –> forgetting to close parentheses, quotation etc.
When do you get a value error?
the operand is okay but the value is illegal
How do you handle exceptions?
Python can provide handlers for exceptions:
try:
body - what to do
except :
print("Bug in ...")What to do when you encounter an error?
What is an assertion?