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
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
-
Structured control flow 5 steps2 practiceabout 20 min
-
Contracts: preconditions and postconditions 6 steps4 practiceabout 22 min
-
Invariants 5 steps3 practiceabout 20 min
-
Defensive programming and testing contracts 4 steps2 practiceabout 18 min
-
Check what you learned 8 questions at the end
Keep exploring
More 10th grade coding
- 10th Grade Coding Worksheets11 printable worksheets
Guide for grown-ups
- How to start homeschooling: a step-by-step guide for familiesA guide for parents · 7 min read