Interface Design Flashcards
Design functions that work together.
mainloop
This tells the window to wait for the user to do something.
Method
Similar to a function but with different syntax, used to request.
bob.fd(100)
.fd is an argument.
for statement (for loop)
Like a function definition, it has a header ending with a colon, followed by an indention and body. The body contains any number of statements.
loop
The flow of execution runs through the body and then loops back to the top.
encapsulation
Wrapping a piece of code into a function, attaching a name to the code.
Generalization
Adding a parameter to a function to make it more general.
Keyword argument
Arguments that include parameter names as “keywords”
polygon(bob, n=7, length=70)
Interface
A summary of how a function is used.
Refactoring
Rearranging a program to improve interfaces and facilitate code re-use.
Development Plan
A process for writing programs. One way is “encapsulation and generalization”:
- Write a small program with no definitions.
- Identify a coherent piece of it, encapsulate it in a function.
- Generalize the function by adding parameters.
- Refactor repeating or similar code into new general functions.
Docstring
String at the beginning of a function explaining the interface. Use triple quotes “””
Preconditions
Conditions that must be true before the function starts executing.
Postconditions
Conditions that include the intended effect of the function.