Note of “Structure And Interpretation Of Computer Programs” (2)

整本书的第一章讲的是过程抽象,即:Building Abstractions with Procedures 第一节关注与简单介绍一下Lisp的基本内容和程序设计基本元素。从第二节开始,内容就关注于介绍过程和抽象的原理。第二节叫过程与它们所产生的计算Procedures and the Processes They Generate。里面提到:

The ability to visualize the consequences of the actions under consideration is crucial to becoming an expert programmer, just as it is in any synthetic, creative activity. In becoming an expert photographer, for example, one must learn how to look at a scene and know how dark each region will appear on a print for each possible choice of exposure and development conditions. Only then can one reason backward, planning framing, lighting, exposure, and development to obtain the desired effects. So it is with programming, where we are planning the course of action to be taken by a process and where we control the process by means of a program. To become experts, we must learn to visualize the processes generated by various types of procedures. Only after we have developed such a skill can we learn to reliably construct programs that exhibit the desired behavior.

A procedure is a pattern for the local evolution of a computational process. It specifies how each stage of the process is built upon the previous stage. We would like to be able to make statements about the overall, or global, behavior of a process whose local evolution has been specified by a procedure. This is very difficult to do in general, but we can at least try to describe some typical patterns of process evolution.

在用过程描述了多个数学算法(求幂、斐波那契数列、检验素数、求最大公约数)之后,第三节开篇这样说道: In effect, abstractions that describe compound operations on numbers independent of the particular numbers.

等我们不再依赖particular numbers之后,就进入了第三节,这章的主题是:用高阶函数做抽象Formulating Abstractions with Higher-Order Procedures。

里面包括:过程作为参数(Procedures as Arguments),过程作为一般性方法(Procedures as General Methods),过程作为返回值(Procedures as Returned Values)

就是在这不断的抽象过程中我们得到越来越强的表达能力,抽象到最后的程序如果变量名起得好的话看起来就像是你的思想过程,这愈发说明了:

1. 编程语言是用来帮助思考程序的,而不是用来表达你已经想好的程序。
2. 程序写出来是给人看的,附带能在机器上运行。

下一章:构造数据抽象,一直懒,没写呢。。待续。。

comments powered by Disqus