Part 2 · Section 05
Project 2
This project revisits the regular polygons from Project 1 with the tools from the previous section. The Polygon class is immutable, so there’s no reason to recompute its area or perimeter every time someone asks; and the Polygons collection stores a list of polygons it may never need. You’ll fix both, turning eager code into lazy code without changing what the classes compute.
- Goal 1: turn every calculated property of
Polygoninto a lazy property, computed at most once and only on demand - Goal 2: replace the list-backed
Polygonssequence with an iterable plus a separate iterator that creates each polygon only when it’s requested - verifying laziness by counting how often work actually happens, not just by checking results
- the auto-graded exercises on the Practice page check correctness and laziness