#python #sicp
the qualities of good functions all reinforce the idea that
functions are abstractions.
If you want to change selection, open original toplevel document below and click on "Move attachment"
Parent (intermediate) annotation
Open itFundamentally, the qualities of good functions all reinforce the idea that
functions are abstractions.
Each function should have exactly one job. That job should be identifiable
with a short name and characterizable in a single line of text. Functions
that perform multiple jobs in sequOriginal toplevel document
1.4 Designing Functionsmall, and
serve as our primary medium to express computational processes in a programming
language. So far, we have discussed the formal properties of functions and how
they are applied. We now turn to the topic of what makes a good function.
<span>Fundamentally, the qualities of good functions all reinforce the idea that
functions are abstractions.
Each function should have exactly one job. That job should be identifiable
with a short name and characterizable in a single line of text. Functions
that perform multiple jobs in sequence should be divided into multiple
functions. Don't repeat yourself is a central tenet of software engineering. The
so-called DRY principle states that multiple fragments of code should not
describe redundant logic. Instead, that logic should be implemented once,
given a name, and applied multiple times. If you find yourself copying and
pasting a block of code, you have probably found an opportunity for functional
abstraction. Functions should be defined generally. Squaring is not in the Python Library
precisely because it is a special case of the pow function, which raises
numbers to arbitrary powers.
These guidelines improve the readability of code, reduce the number of errors,
and often minimize the total amount of code written. Decomposing a complex task
into concise functions iSummary
status | not read | | reprioritisations | |
---|
last reprioritisation on | | | suggested re-reading day | |
---|
started reading on | | | finished reading on | |
---|
Details