Week 7 Day 1 - Using Invariants to Debug Linked Lists
A good way to look at code and write code is to think about what invariants need to be preserved. An invariant is something that will always be true about your class, both before and after any function call. Once you know what must be done, you can look at your functions and see if you're maintaining them properly.
I first showed how I used that philosophy when writing a delete function for linked lists (and combined it with thinking about edge cases as well).
I then showed how to use this approach when debugging code. (Debugging other people's code helps build experiences, so I highly recommend becoming an undergraduate TA if you can.) By looking at which invariants were in a function, you can immediately spot some bugs without really even needing to read it closely.
We then went through some actual student code, and saw a lot of different ways linked list code can go badly. Never preserve a reference to a local variable, and always sketch out your code to make sure that it's doing what you think it is doing!
Other Videos By Bill Kerney
2021-02-28 | Week 7 |
2021-02-28 | Week 7 Day 3 - Deep Copies, Stacks |
2021-02-27 | Week 6 Day 3 - Moar Midterm Review |
2021-02-25 | Week 7 Day 2 - Vector Math |
2021-02-25 | Week 7 Day 2 - Pipelining |
2021-02-24 | Week 7 Day 2 - Debugging II and Queues |
2021-02-24 | Week 6 Day 2 - Midterm Review |
2021-02-23 | Week 7 Day 1 - The Triangle in Games |
2021-02-23 | Week 7 Day 1 - Classes in C and Assembly |
2021-02-23 | Week 6 Day 1 - Fallacies III |
2021-02-22 | Week 7 Day 1 - Using Invariants to Debug Linked Lists |
2021-02-20 | Week 5 Day 2 - Fallacies II |
2021-02-19 | Week 6 - Auto Landscapes |
2021-02-19 | Week 6 Day 2 - Linked Lists Part III |
2021-02-18 | Week 6 Day 2 - Auto Landscapes |
2021-02-18 | Week 6 Day 2 - Range Based Loops in Assembly |
2021-02-17 | Week 5 Day 1 - Invalid / Valid / Sound Arguments II |
2021-02-17 | Week 6 Day 1 - C++ Trivia: Const |
2021-02-16 | Week 6 Day 1 - Water and Landscapes III |
2021-02-16 | Week 6 Day 1 - Midterm Review and Generations of Architectures |
2021-02-12 | Week 4 Day 3 - Invalid / Valid / Sound Arguments |