More striking is the use of indentation. Although it was common in programs written in ALGOL 60 or its descendants, such as Pascal, to use indentation as a typographical layout feature for clarifying the grouping of commands, this was an entirely optional presentation choice, made purely for the benefit of the human reader. In an article by P. J. Plauger entitled “Signal and Noise in Programming Languages,”16 we found the (then) radical idea to “have the compiler read the same signal as we human beings, and let the indenting control grouping,” a suggestion we followed with enthusiasm. Indentation to indicate that a suite of commands belong together subsequently became mandatory in B0 programs, a design choice that has been maintained throughout all iterations.17
——节选自《The Origins of Python》
简单概括:当时在设计新的编程语言时,他们受到了一篇文章的强烈影响,决定仅采用缩进语法来控制代码块的分组。核心思想是“have the compiler read the same signal as we human beings”,为了代码简洁性及理解一致性,舍弃了其它的代码分组方案。
上文提到的文章标题为《编程语言中的信号与噪声》(Signal and Noise in Programming Languages),发表于 1975 年的 ACM 年会论文集,作者 P.J. Plauger 是全球知名的计算机科学家、C/ C++技术专家以及 The Standard C Library、Standard C : A Reference 和 The Standard Template Library 等图书的作者。
该篇文章想要区分编程语言的哪些语法是对读者有用的信号、哪些仅是无用的噪声。文中提到了一个编程理论:“常说的东西应该言简意赅(things which get said a lot should be concise)”。
由于代码经常要分组分块,因此,“信号与噪声”一文将begin...end 及do...end 这两种当时常见的代码分组语法批评为糟糕的设计。它不反对花括号“{...}”的语法设计,但是提出了一种更为激进的设计,也就是仅用缩进来控制代码分组(let the indenting control grouping)。
另外,《The Origins of Python》中还提供了两个比《编程语言中的信号与噪声》更早的起源:
1965 年的 ISWIM 编程语言(“If you See What IM
ean”的首字母缩写)。它可能是有据可考最早使用缩进分组代码块的语言(尽管它没有实现),其设计者在《The Next 700 Programming Languages》中称之为“Off-side rule”(越位规则)
1974 年唐纳德·克努特(Donald Knuth,著名计算机科学家、图灵奖获得者,经典巨著《计算机程序设计艺术》的作者)发表在 ACM 通讯的文章《 Structured Programming with Go To Statements》,他在畅想未来的编程语言时说:We will perhaps eventually be writing only small modules which are identified by name as they are used to build larger ones, so that devices like indentation, rather than delimiters, might become feasible for expressing local structure in the source language。
值得注意的是,唐纳德提供的参考材料正是 1965 年 ISWIM 之父的文章《The Next 700 Programming Languages》,里面收录了多位大佬对于缩进的讨论观点。