How to Design Programs

Table of Contents

https://htdp.org/2019-02-24/part_one.html

1. The basic steps of a function design recipe

  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.

2. What is a good program?

A good program reflects the problem statements and its important concepts. It comes with a concise self-description. Examples illustrate this description and relate it back to the problem. The examples make sure that the future reader knows why and how your code works. In short, good programming is about solving problems systematically and conveying the system within the code.

3. What are programming languages about?

Programming languages are about computing with information, and information comes in all shapes and forms. For example, a program may deal with colors, names, business letters, or conversations between people. Even though we could encode this kind of information as numbers, it would be a horrible idea. Just imagine remembering large tables of codes, such as 0 means "red" and 1 means "hello," and the like.

4. 就编程而言,{{c1::「算术」}}是游戏的一半,另一半是{{c1::「代数」}}。

5. 编程需要哪些代数概念?

变量、函数定义、函数应用和函数组合。

6. 有哪些应用类型?

  • 批处理程序:一次处理大量数据然后返回
  • 交互式程序:根据不同输入事件,返回相应反馈

7. 程序的目的是什么?

描述一个消费一些信息并产生新信息的过程。

8. 有哪些型式的领域知识?

  • 程序的外部领域知识:如音乐、文学、历史、生物等。
  • 所选语言的库函数的了解。