CS116 Study Guide - Quiz Guide: Mutation

106 views2 pages

Document Summary

Changes to the design recipe to accommodate mutation. Mutation allows for functions to do more than algebraic manipulation of their arguments. In particular, a function can change the value of a variable, or can have other side effects. This is explored in some depth in section 36. 4 of how to design programs. These are the elements of the modified design recipes for programs using mutations: State variables are the way that we store the values that may change over the execution of a program. For these variables, if they exist, define them and give them a value. The contract should describe the consumed value(s) and the produced value(s) of the function. Use (void) to indicate that the function has no consumed values, and use (void) to indicate the function has no produced values. The purpose of a function should describe what the function consumes and produces.