Programming By Strengthening Of Invariants

Bart Massey 2013-11-07


  • Misc notes
  • Quiz
  • Programming by strengthening of invariants
  • In-class programming demo

Misc Notes


  • In-class quiz

Programming By Strengthening Of Invariants

  • Upon input, your routine may have complicated state

    • Messy parameters

    • Unknown global and module state

  • Idea: Program by successively handling messy side cases until you get to the main case

    • With each handled case, return from the routine

    • Within a case, use break and continue inside loops to get to return points

  • End result: Code that reads cleanly top-to-bottom, with each section performing a clear and useful function

Establishing Invariants

  • At the start of each handled case, indicate with a comment what is being handled and why

  • Implicitly (else explicitly) be able to give an account of invariants (things that must be true) after every statement

  • Invariants should get stronger and stronger, making the code easier and easier


  • In-class demo of programming by strengthening invariants
Last modified: Wednesday, 6 November 2013, 11:10 PM