《HTDP》小记

这个世界究竟还是有些浮躁,在一堆堆“快消品”之间,很少看见有人能够拥有工匠精神。但,编程从不是一件随随便便的事情,我也从不认同程序员等同于码农。

思考

摘录一些书中等同身受的观点。


program design—but not programming—deserves the same role in a liberal-arts education as mathematics and language skills.

程序设计 —— 而不是编程 —— 在人文教育中的地位应该与数学和语言技能一样重要。


programming differs from good programming like crayon sketches in a diner from oil paintings in a museum.

良好编程不同于编程,就好比小餐馆中的蜡笔素描不同于博物馆中的油画。


By “good programming,” we mean an approach to the creation of software that relies on systematic thought, planning, and understanding from the very beginning, at every stage, and for every step.

“良好编程”指的是创建软件的方法,软件从一开始就在每个阶段和每一步都依赖系统的思考、规划和理解。


To emphasize the point, we speak of systematic program design and systematically designed programs.

为了强调这一点,我们会讨论 系统的程序设计 和 系统地设计的程序。


“systematic program design” refers to a mix of two concepts: design recipes and iterative refinement.

“系统的程序设计”指的是两个概念的混合:设计诀窍和迭代改进。

recipes从菜谱/食谱的理解上入手,感觉会更好一些。


The function-level design recipes share a common design process.

six essential 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.

函数级别的设计诀窍共享相同的设计过程。

函数设计诀窍的6个基本步骤:

  1. 从问题分析到数据定义

    确定必须要表示的信息,以及如何使用选择的编程语言表示信息。编写数据定义,并用示例说明之。

  2. 签名、目的声明、头部

    声明所需函数输入和输出的数据类型。为函数计算什么编写简明的答案。定义符合签名的stub。

  3. 函数示例

    通过示例说明函数的用途。

  4. 函数模版

    将数据定义翻译为函数的提纲。

  5. 函数定义

    填写函数模版中的空白。需要用到目的声明和示例。

  6. 测试

    将示例表示为测试,并确保函数通过所有测试。这样就可以发现错误。测试也是示例的补充,它们可以帮助其他人在需要时阅读和理解定义,对于重要的程序,这种需求就会出现。

上述6个基本步骤的过程描述,表明设计师必须:

  1. 分析问题陈述,通常以文字表达;
  2. 抽象地提炼并表达其本质;
  3. 用示例说明其本地;
  4. 根据此分析指定大纲和计划;
  5. 评估有关预期产出的结构;
  6. 依据检查和测试失败修改产品。

When a novice is stuck, an expert or an instructor can inspect the existing intermediate products, and thus drive the novice to correct himself or herself. This self-empowering process is the key difference between programming and program design.

当新手遇到问题被卡住时,专家或讲师可以检查现有的中间产品,从而促使新手自行纠正。这种自主赋权过程正是编程和程序设计之间的本质区别。


Iterative Refinement addresses the issue that problems are complex and multifaceted. In essence, iterative refinement recommends stripping away all inessential details at first and finding a solution for the remaining core problem. A refinement step adds in one of these omitted details and re-solves the expanded problem, using the existing solution as much as possible. A repetition, also called an iteration, of these refinement steps eventually leads to a complete solution.

迭代改进可以解决复杂而多面的问题。本质上,迭代改进建议首先剥离所有不必要的细节,并找到剩余核心问题的解决方案。每个改进步骤添加回其中一个被省略的细节,同时尽可能使用现有解决方案重新解决拓展后的问题。这些改进步骤的重复(也成为迭代)最终通向完整的解决方案。


learning to design programs is primarily about the study of principles and the acquisition of transferable skills.

学习程序设计的关键是关于原则的研究和可转移技能的获取。


The design of a program proceeds in a top-down planning phase followed by a bottom-up construction phase.

程序设计分为自上而下的计划阶段,以及自下而上的构建阶段。