聚合国内IT技术精华文章,分享IT技术精华,帮助IT从业人士成长

为什么我觉得编程就像施魔法一样?

2012-06-23 03:00 浏览: 2007451 次 我要评论(0 条) 字号:


心智的活动,除了尽力产生各种简单的认识外,主要表现在如下三个方面:

  1. 将若干简单的认识组合为一个复合认识,由此产生出各种复杂的认识;
  2. 将两个认识放在一起对照,不管它们如何简单或者复杂,在这样做时并不将它们合而为一;由此得到有关它们的相互关系的认识;
  3. 将有关认识与那些在实际中和它们同在的所有其它认识隔离开,这就是抽象,所有具有普遍性的认识都是这样得到的。

在大英百科全书关于“分类学理论”中提出,人类在认识和理解现实世界的过程中,普遍运用着三个构造法则:

  1. 区分对象及其属性,例如,区分一棵树和树的大小或空间位置。
  2. 区分整体对象及其组成部分,例如,区分一棵树和树枝。
  3. 不同对象类的形成及区分,例如,所有树的类和所有石头的类的形成和区分。

我们准备学习的是有关计算过程的知识。计算过程是存在于计算机里的一类抽象事物,在其演化进程中,这些过程会去操作一些被为数据的抽象事物。人们创建出一些称为程序的规则模式,以指导这类过程的进行。从作用上看,就像是我们在通过自己的写作魔力去控制计算机里的精灵似的。

一个计算过程确实很像一种神灵的巫术,它看不见也摸不到,根本就不是由物质组成的。然而它却又是非常真实的,可以完成某些智力性的工作。它可以回答提问,可以通过在银行里支付现金或者在工厂里操纵机器人等等方式影响这个世界。我们用于指挥这种过程的程序就像是巫师的咒语,它们是用一些诡秘而深奥的程序设计语言,通过符号表达式的形式精心编排而成,它们描述了我们希望相应的计算过程去完成的工作。

在正常工作的计算机里,一个计算过程将精密而准确地执行相应的程序。这样,初学程序设计的人们就像巫师的徒弟们那样,必须学习如何去理解和预期他们所发出的咒语的效果。程序里即使有一点小错误(常常被称为程序错误或者故障),也可能产生复杂而无法预料的后果。

幸运的是,学习程序的危险性远远小于学习巫术,因为我们要去控制的神灵以一种很安全的方式被约束着。而真实的程序设计则需要极度细心。需要经验和智慧。例如,在一个计算机辅助设计系统里的一点小毛病,就可能导致一架飞机或者一座水坝的灾难性损毁,或者一个工业机器人的自我破坏。

软件工程大师们能组织好自己的程序,使自己能合理地确信这些程序所产生的计算过程将能完成预期的工作。他们可以事先看到自己系统的行为方式,知道如何去构造这些程序,使其中出现的意外问题不会导致灾难性的后果。而且,在发生了这种问题时,他们也能排除程序中的错误。设计良好的计算系统就像设计良好的汽车或者核反应堆一样,具有某种模块化的设计,其中的各个部分都可以独立地构造、替换、排除错误。

The acts of the mind, wherein it exerts its power over simple ideas, are chiefly these three: 1. Combining several simple ideas into one compound one, and thus all complex ideas are made. 2. The second is bringing two ideas, whether simple or complex, together, and setting them by one another so as to take a view of them at once, without uniting them into one, by which it gets all its ideas of relations. 3. The third is separating them from all other ideas that accompany them in their real existence: this is called abstraction, and thus all its general ideas are made.

We are about to study the idea of a computational process. Computational processes are abstract beings that inhabit computers. As they evolve, processes manipulate other abstract things called data. The evolution of a process is directed by a pattern of rules called a program. People create programs to direct processes. In effect, we conjure the spirits of the computer with our spells.

A computational process is indeed much like a sorcerer's idea of a spirit. It cannot be seen or touched. It is not composed of matter at all. However, it is very real. It can perform intellectual work. It can answer questions. It can affect the world by disbursing money at a bank or by controlling a robot arm in a factory. The programs we use to conjure processes are like a sorcerer's spells. They are carefully composed from symbolic expressions in arcane and esoteric programming languages that prescribe the tasks we want our processes to perform.

A computational process, in a correctly working computer, executes programs precisely and accurately. Thus, like the sorcerer's apprentice, novice programmers must learn to understand and to anticipate the consequences of their conjuring. Even small errors (usually called bugs or glitches) in programs can have complex and unanticipated consequences.

Fortunately, learning to program is considerably less dangerous than learning sorcery, because the spirits we deal with are conveniently contained in a secure way. Real-world programming, however, requires care, expertise, and wisdom. A small bug in a computer-aided design program, for example, can lead to the catastrophic collapse of an airplane or a dam or the self-destruction of an industrial robot.

Master software engineers have the ability to organize programs so that they can be reasonably sure that the resulting processes will perform the tasks intended. They can visualize the behavior of their systems in advance. They know how to structure programs so that unanticipated problems do not lead to catastrophic consequences, and when problems do arise, they can debug their programs. Well-designed computational systems, like well-designed automobiles or nuclear reactors, are designed in a modular manner, so that the parts can be constructed, replaced, and debugged separately.



网友评论已有0条评论, 我也要评论

发表评论

*

* (保密)

Ctrl+Enter 快捷回复