Recitation 05: Debugging and Linear Search
Before we get to debugging, remember that a little extra work up front
can save you a lot of time and frustration in the long run. Test and debug
incrementally. So, after you write a function, test it to make sure
everything works as expected. It'll be a lot easier to find that bug in
foo() than later when the bug happens once bar() calls
For these examples, some notes can be found in a comment at the top of
- See code linked above.
- Pay attention to the is_in() function, since we'll be using
it in our annotations.
- As an activity to better understand how contracts work together, it
may be worth while to connect the contracts together. For example, which
loop invariant supports which postcondition? They usually have a very
similar function and are easy to identify.
- What if we want to find the index of the last occurance of the
element instad of the first occurance? Change the code accordingly. [code]
If you have any comments or see any errors, please
let me know.