An implementation is the concrete way an algorithm, task, or object behavior is realized through steps and actions. A useful workflow is think, code, test, debug, and repeat: understand the task, write a possible solution, compare actual results with expected results, fix incorrect behavior, and continue until the tests pass. section 2.3
Keep the task separate from its implementation when planning a program:
- Treat a large task as smaller black-box tasks. Focus first on each task’s purpose, inputs, and outputs rather than its internal steps. section 20.1
- Make each task a repeatable sequence of actions with clearly documented inputs and outputs. section 20.1
- Hide unnecessary implementation details so users can understand and use a behavior without knowing how it works internally. section 20.1 section 32.1
Implementing a stack
A stack can first be simulated with a list: add items at the end and remove items from the end. A Stack class turns those rules into methods such as add_one, remove_one, size, and prettyprint. The list becomes an internal data attribute, while users work with the stack’s behaviors instead of managing the list directly. section 32.1
Figure 2.3. This is the ideal way to approach solving a problem with programming. Understand the problem before you write any code. Then test the code that you write and debug it as necessary. This process repeats until your code passes all tests.
Follow the repeated implementation cycle from understanding the problem through testing and debugging until the program passes its tests. section 2.3
