Skip to content
PlayOwl

Coding · Grade 10

Structured Programming and Design Contracts

Using a school print-credit system, learners write structured code with guard clauses instead of deep nesting, specify functions with preconditions, postconditions and clear exceptions, protect data invariants in a class, and practise defensive programming by testing both sides of each contract and checking that refusals leave state unchanged.

  • 4 lessons
  • About 90 minutes
  • Check what you learned: 8 questions
  • Ways to answer: fill in the blanks, choose an answer, trace code, match pairs, type a number and sort into groups
Try it now (no account) One of the five free starter courses Open in PlayOwl

What learners will discover

  • Write structured control flow with guard clauses and shallow nesting, and refactor without changing behaviour.
  • Specify functions with preconditions, postconditions and exceptions raised on violation.
  • Establish and preserve loop and data invariants, checking them with assertions.
  • Apply defensive programming and test contracts on both sides, including state after refusals.

Lessons

  1. Structured control flow 5 steps2 practiceabout 20 min
  2. Contracts: preconditions and postconditions 6 steps4 practiceabout 22 min
  3. Invariants 5 steps3 practiceabout 20 min
  4. Defensive programming and testing contracts 4 steps2 practiceabout 18 min
  5. Check what you learned 8 questions at the end

Keep exploring

More 10th grade coding

Guide for grown-ups