Software Design and Implementation
P4: Debugging
Paired assignment P4 should be completed with a partner.
Watch the portion of the following video from 4:43 to 13:04 on debugging in PyScripter:The above video at http://www.youtube.com/watch?v=KRb727NqmeA demonstrates some key ideas of the PyScripter environment as one does a debug run of a complex program. You can start at 4:43, as the first part is an introduction, and you can stop at 13:04 because the rest is review. Here is some of the code used in the video which you can right-click to download:
Some highlights from the video and about debugging with PyScripter:
- Breakpoints (5:08 minutes) are lines in your program that you have indicated where PyScripter should stop running the code so that you can see a "snapshot" of what the variable values are on that line. At (9:40 minutes), there is an example of setting a breakpoint INSIDE a function, which is very useful.
- The debug (5:32 minutes) button at the top starts the debug mode rather than simply running your program so that it will stop at your breakpoints. Clicking on the button again after reaching a breakpoint will resume running your program until it ends or another breakpoint is reached.
- The variables (6:43 minutes) tab at the bottom gives you a list of all the variables that are defined and have value in the program. Note how PyScripter will not display a variable UNTIL it is actually used.
- Stepping into subroutines (8:11 minutes) will cause PyScripter to "enter" into a function that is called at that line. You will jump to the point that the function starts, and you can run one step at a time of the called function.
- Stepping out of a subroutine (8:37 minutes) will cause the PyScripter interpreter to execute the rest of the lines in a function and pause after the function call is over.
- The Watches tab (11:03 minutes) allow you to select which variable you want to keep track of, rather than all the variables. At (12:30), you can see using watches how local variables disappear after the function using them finished.
- The Abort Debugging button exits debug move and enables regular runs of your program once you are done debugging.
Here are some buggy python code samples which you and your partner will fix in this assignment:
- debug-making-change.py (right-click to download)
- debug-birthday.py (right-click to download)
- debug-circle.py (right-click to download)
The instructions
This Paired Assignment has several steps:- Remember that the primary objective is to learn to use the
debugger effectively, so please do not think that the objective is
to just fix the errors--fixing the errors is just a vehicle to
using the debugger.
- Create a new folder called yourusernames-p4 into which you will return repaired programs:
- Download the buggy python code samples which you and your
partner will fix in this assignment:
- debug-making-change.py and rename yourusernames-change.py
- debug-birthday.py and rename yourusernames-birthday.py
- debug-circle.py and rename yourusernames-circle.py
- In the header of each of these programs, put both partners names as having modified the code. Also, include the role each partner played. e.g. navigator, driver, etc.
- For each of these programs, look carefully at the syntax and flow of control. Each of these programs has multiple problems which you should repair.
- Be sure to add comments to the code describing each of the things you fix and why you needed to fix them.
- When complete, put these programs in the folder, zip the folder, and upload into Moodle.
- Remember that you only need to submit a single folder per team and that you must include both team members' names and the roles you had in each of the python program files. It is also a good idea for the partner who is not submitting to upload the name of his or her partner.
Note that submitted files with incorrect filenames may not receive full credit because it makes grading more difficult for us and the TAs, so please check filenames carefully!
Also, be sure to read for Q7: On the Appendix A: Debugging reading from How to Think Like a Computer Scientist