How to Design Programs - Prologue

  1. Hence any reasonably complete program consists of many building blocks: some deal with input, some create output, while some bridge the gap between those two.

1. From Problem Analysis to Data Definitions
    Identify the information that must be represented and how it is represented in the chosen programming language. Formulate data definitions and illustrate them with examples.

2. Signature, Purpose Statement, Header    
    State what kind of data the desired function consumes and produces. Formulate a concise answer to the question what the function computes. Define a stub that lives up to the signature.

3. Functional Examples
    Work through examples that illustrate the function’s purpose.
4. Function Template
    Translate the data definitions into an outline of the function.
5. Function Definition
    Fill in the gaps in the function template. Exploit the purpose statement and the examples.
6. Testing
    Articulate the examples as tests and ensure that the function passes all. Doing so discovers mistakes. Tests also supplement examples in that they help others read and understand the definition when the need arises—and it will arise for any serious program.
  1. Design Recipes apply to both complete programs and individual functions.

  2. Iterative Refinement addresses the issue that problems are complex and multifaceted. Getting everything right at once is nearly impossible. Instead, computer scientists borrow iterative refinement from the physical sciences to tackle this design proble

  3. functions are like expressions, always with a y on the left, followed by an = sign, and an expression.

  4. (FunctionName ArgumentExpression) - is a function application. The first part tells function you wish to use. The second part is the input to which you want to apply the function.

  5. Acquiring the mechanical skills of programming—learning to write expressions that the computer understands, getting to know which functions and libraries are available, and similar activities—isn’t helping you all that much with real programming. If it were, you could equally well learn a foreign language by memorizing a thousand words from the dictionary and a few rules from a grammar book.

  6. Good programming is far more than the mechanics of acquiring a language. Most importantly, it is about keeping in mind that programmers create programs for other people to read them in the future.

标签: none

添加新评论