JOVANA
Library Glossary Getting Started Three Levels Fields How it works Mission
Join the mission
Back to the library
编程语言 1957

FORTRAN 自动编码系统

约翰·巴科斯 等(IBM)

写数学,而不是机器的地址——让一个程序把它编译成不输于人手的代码。

Choose your version
In depth · the introduction

1957 年以前,告诉计算机做什么,意味着用它原始的数字语言,一个地址一个地址地亲手去写。FORTRAN 让你改写数学——剩下的,交给机器。

核心想法

计算机只懂得一长串细小的、带编号的命令——把这个数取来、把那个数加上、把结果存到这里。亲手写这些清单又慢、又枯燥、又容易出错。FORTRAN 一并带来了两样东西:一种高级语言,让你写下贴近普通代数的式子;以及一个编译器——一个会读你的公式、替你写出机器所有细小命令的程序。

于是,你不必再写几十条晦涩的指令,只需写一行——Y = A*X**2 + B*X + C——编译器就会自动把它翻译成快速的机器代码。最大胆之处在于:当时没人相信机器能把这种翻译做得足够好。FORTRAN 的编译器证明了它能:它产出的代码,跑得几乎和人类专家手写的一样快。

它是如何诞生的

项目于 1954 年在 IBM 启动,由一位名叫约翰·巴科斯的年轻研究者领导,为 IBM 强大的新机器 704 而作。那时,仅仅为一个问题做准备——写程序、调试程序——的花费,就超过了计算本身。巴科斯的主张,是用自动编码把这笔花费砍下来。

他遇到了深深的怀疑。专家程序员以亲手雕琢紧凑的机器代码为荣,不信任何自动系统能与他们比肩。于是巴科斯的团队把「效率」当成执念:编译器不只翻译,还要优化,竭力把机器稀缺的快速寄存器用在刀刃上。这花了约三年,以及一场浩大的编程苦工。当 1957 年编译器交付时,它成了——怀疑者,也被折服了。

它为何重要

FORTRAN 把编程,向真正手握问题的人——科学家与工程师——敞开,而不再把它锁在一小撮机器代码祭司手中。它让软件的编写大幅变便宜、变快,并在此过程中,帮助催生了软件产业本身。我们今天挂在嘴边的词——编译器、高级语言——正是经由它,走入了寻常用语。

一个可以想象的画面

想想乐谱。作曲家用干净、可读的记法写下一段旋律——纸上寥寥几行。技艺娴熟的演奏者,再把每一个音符,化作真正发出声音的、精确而飞快的指间动作。FORTRAN 就是那位演奏者:你写下可读的记法,编译器便一音一音地,把它演绎成机器必须做出的成千上万个精确的小动作——而且,演绎得几乎不输于最高明的那双手。

输入一条算术公式,组件会把它编译成一份带编号的清单,列出计算机必须按正确顺序执行的那些小步骤,显示一行可读的公式如何展开成许多步。

它的位置

FORTRAN 并非自动编程的最初尝试——格蕾丝·霍珀早已造出过早期编译器,也有人试过代数系统——但它是第一个既高效、又被广泛采用的,正因如此才扎下了根。它之后,语言如潮水般涌来:ALGOL、COBOL、BASIC、C,以至后来的 Python。对它那缠绕的 GO TO 风格的反弹,则把埃兹格·迪杰斯特拉等人引向了结构化编程——这条线索,你可以在本馆别处接着追下去。

The original document
Original source text
J. W. Backus, R. J. Beeber, S. Best, R. Goldberg, L. M. Haibt, H. L. Herrick, R. A. Nelson, D. Sayre, P. B. Sheridan, H. Stern, I. Ziller, R. A. Hughes, R. Nutt · Proc. Western Joint Computer Conference (1957): 188–198
Why it was built
By the mid-1950s, writing and debugging a program by hand — in the IBM 704's raw numeric code, juggling memory addresses and index registers — had become the dominant cost of using a computer. The FORTRAN team's aim was to let a programmer state a numerical procedure in a concise notation close to mathematics, and have the machine produce automatically an efficient 704 program to carry it out.
The language
FORTRAN gave the programmer arithmetic assignment statements written like algebra (with the precedence ** before × and ÷, before + and −), variable and array names of up to six characters declared by DIMENSION, formatted input/output, the GO TO branch, the counting DO loop, and the three-way arithmetic IF. Two of its most characteristic lines:
DO 5 I = 1, 10
The DO statement repeats every statement down to the one labelled 5, for I running 1, 2, … 10 — the ancestor of the counting loop in every language since. The other:
IF (X) 10, 20, 30
The arithmetic IF jumps to statement 10 if X is negative, to 20 if it is zero, and to 30 if it is positive — branching directly on the sign of an expression.
The translator
The compiler ran in six sections. Its celebrated, hardest work was optimization: it analysed the flow through nested DO loops, treated array subscripts as functions of the loop indices, and allocated the 704's three index registers across each region of the program using a frequency analysis of how often each path would run — keeping the busiest indices in registers. This was register allocation and loop optimization, decades before those names existed.
What it set out to do
The project's overriding aim was that the object program should be nearly as efficient as one a good programmer would write by hand — otherwise no one would trust a high-level language — while cutting the labour of coding and debugging to a fraction of what it had been. Meeting both goals at once was the achievement.
[ … ]
IBM · 1957