Lab 8 Function Testing and Debugging
Solutions
Summary
- Reminder: Be a good partner
- Function Testing
- Debugging
Lab Setup
- Find your partner
- Use CyberDuck to SFTP into one of your accounts on the
cs.wellesley.edu
server - On the server, navigate to the
cs111/download
folder - Download the
lab08
folder to your Desktop (by dragging and dropping it from the CyberDuck window) - Open Canopy and load the
lab08
folder in the Canopy File Browser pane
Pair Programming Tips
1. Recognize that pairing is hard
Pairing is an intense relationship, summoning all your powers of ingenuity, communication, humour, and code. If you find it hard, or even just tiring, it's because it is hard and tiring sometimes. It takes effort to be kind, patient and to help steer someone in the right direction. Respect your partner and be kind. Your job is to help each other learn.
2. Be mindful of your body language
Is your back to your partner? Is your computer screen angled away? Do you make eye contact? You want to create an atmosphere of inclusion so your pair feels respected and encouraged to comment.
3. Is it too quiet between you and your partner?
If there is a lot of silence, that is often a sign that someone feels left behind. Did you take over the keyboard and write a bunch of lines in silence? Yikes! Explain what you type to your partner. Or perhaps you are confused but feel uncomfortable speaking up. Try: "I don't understand this line, can you explain what it does?"
[some content from https://www.fiddlerscode.com/blog/10-tips-for-great-pair-programming]
Table of Contents
Big Questions
- How much extra time does it take to write tests for your code?
Show Answer
This is a trick question! If you write your tests after writing your code, for most CS 111 problems, it should take no more than 15-30 minutes to write a few tests and run them to make sure your code is working. However, if you write tests *before* you write your code, the same 15-30 minutes spent writing tests is likely to save you at least 30 minutes to an hour of development time for two reasons: you will have a clearer understanding of the problem when you start coding, and when you have a version that you think is working, you can immediately test it to see if it is, and your tests will help tell you what isn't working. - What do you think are the two most important debugging techniques?
Show Answer
- Adding
print
statements to your code to understand what is actually happening instead of guessing what the problem is. This is called "tracing." - Commenting out code to see what changes. Along with
print
statements to tell you what is going on, this is your most powerful tool to figure out which parts of your code are doing what you want and which parts are doing something unexpected. Don't be afraid to work with multiple versions of the code and see how they behave to help narrow down why a bug is happening.
- Adding