Designing Programs
Approach Until Now Pick smallest meaningful step you can do Goto 1 Do it Test it Goto 1
New Approach Can I do it in ~10 lines? Yes: Do it No: Break the problem down into smaller tasks Define each in terms of input and output With each task, go to 1
Reasons For Functions Reuse code:
Reasons For Functions Create abstractions: Detailed Abstracted
When To Function Reusing same code in multiple locations Want to provide abstraction Existing code is too complex
How To Function A good function Does exactly one job
How To Function A good function Does exactly one job Has clear inputs/outputs
How To Function A good function Does exactly one job Has clear inputs/outputs Is the right length Probably Not Maybe Sure
Comparison Monolithic vs Modular…
Stepwise Refinement Take problem Break into subproblems With each subproblem: Can you implement it easily? Yes : Done No : Goto 1 with this problem
Building a Program Goal: Display month calendar given year, month
Break Down
Break Down
Break Down
Break Down
Break Down
Break Down
Break Down
Bottom Up Implement low level functions, test individually
Top Down Implement top level functions using stubs for lower level ones
Real World Development is cyclical Make plan Code to plan Learn stuff Goto 1