Designing Functions
functions do not add any computational power to the language
na function definition simply encapsulates other statements
still, the capacity to define and use functions is key to solving complex problems, as well as to developing reusable code
nencapsulating repetitive tasks can shorten and simplify code
nfunctions provide units of computational abstraction – user can ignore details
nfunctions are self-contained, so can easily be reused in different applications
n
when is it worthwhile to define a function?
nif a particular computation is complex—meaning that it requires extra variables and/or multiple lines to define
nif you have to perform a particular computation repeatedly within a page
n
when defining a function, you must identify
nthe inputs
nthe computation to be performed using those inputs
nthe output