灯下 登录
计算机科学 / SICP / section 中英对照

1.2 Procedures and the Processes They Generate

We have now considered the elements of programming: We have used primitive

arithmetic operations, we have combined these operations, and we have

abstracted these composite operations by defining them as compound procedures.

But that is not enough to enable us to say that we know how to program. Our

situation is analogous to that of someone who has learned the rules for how the

pieces move in chess but knows nothing of typical openings, tactics, or

strategy. Like the novice chess player, we don’t yet know the common patterns

of usage in the domain. We lack the knowledge of which moves are worth making

(which procedures are worth defining). We lack the experience to predict the

consequences of making a move (executing a procedure).

我们现在已经考察了程序设计的各种基本要素:使用过基本算术运算,组合过这些运算,并通过将组合运算定义为复合过程来加以抽象。但这还不足以让我们说已经懂得了如何编程。我们的处境好比一个学会了棋子走法规则却对常见开局、战术和策略一无所知的象棋初学者。与那位新手一样,我们尚不了解此领域中常见的使用模式——不知道哪些招法值得走(哪些过程值得定义),也没有经验去预判走出某步棋的后果(执行某个过程的结果)。

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 this section we will examine some common “shapes” for processes generated

by simple procedures. We will also investigate the rates at which these

processes consume the important computational resources of time and space. The

procedures we will consider are very simple. Their role is like that played by

test patterns in photography: as oversimplified prototypical patterns, rather

than practical examples in their own right.

本节将考察由简单过程所生成的计算过程的几种常见“形状”,并研究这些计算过程消耗时间和空间这两种重要计算资源的速率。我们要考察的过程非常简单,它们的作用犹如摄影中的测试图案:作为过度简化的原型模式,而非各自独立的实际示例。