cover image: General Debugging Practices

Premium

General Debugging Practices

2024

One of the important things we hope to teach you in 122 is how to debug your code. [...] Once you have identied this failure, your next goal is to nd the "smallest possible" test case that exhibits this same failure. [...] Once you have reduced your test case to the smallest possible, your next goal is to narrow down the problem by continuing the I expected... [...] One great way to do this is to trace through your test case on paper, try to gure out where your paper function diverges from the one you implemented. [...] One way to determine where your paper function diverges from the one you implemented is by adding print statements. If you're unsure on where the best place to put print statements is, it may be worth reading the Debugging with Print Statements guide. [...] A third way to determine where your paper function diverges from the one you implemented is by commenting out sections of code. [...] Error messages are one of your best windows into what is going on so take the time to read them! If you are unsure as to what an error message is saying, feel free to post on Ed or ask a TA at oce hours! Furthermore, a great tool for debugging is Talking through the code with yourself. [...] Write local test cases until one fails. Read through the Writing a Test File guide if you are unsure about how to write test cases. 3. [...] 4 How do I test my code A great tool for guring out how to test your code is the Writing a Test File guide. [...] A short list of some important and useful concepts in that guide for how to write good test cases is as follows: • Often we give you examples in the writeup.
Pages
3
Published in
United States of America