Review, explain, practice

Study guide: Organize Programs into Clear Responsibilities

Design a paper helper for doubling a nonnegative integer count. State its contract, distinguish return from printing and give a valid example without modifying shared state.

Download the grade study pack

Ideas to explain in your own words

Useful vocabulary

return
Send a result back to the caller.
local variable
A value scoped to the stated call’s work.
contract
The accepted inputs and promised behavior of a helper.

Watch your reasoning

A worked review example

Function returns 5 and prints nothing. Classify the stated function behavior. The supported answer is Returns only. Track the caller’s returned value separately from visible output. Do not substitute printed text for the return value. A function can return a value to its caller, print a visible message, do both, or do neither. Accepts a nonnegative whole-number count. Classify this contract statement. The supported answer is Input requirement. Match the requested documentation element to its role in the contract. An example is useful but does not replace an input rule. A function contract states accepted inputs, produced outputs and important conditions. The supplied facts, rather than an assumed real-world detail, determine this paper case. Compare the recorded action or value with the stated rule before choosing an answer.

Make a practice plan

  1. Make a four-row summary, one row for each lesson, with its computing idea and one worked decision.
  2. Explain one tempting mistake using the actual supplied example.
  3. Complete the new unit review before consulting its explanations.
  4. Try the transfer task on paper and compare your evidence against the model response.