Glean 拾遗
专辑 / Paul Graham 文集 / 简洁即力量:编程语言设计的核心原则

简洁即力量:编程语言设计的核心原则

原文 www.paulgraham.com 收录 2026-07-07 16:36 阅读 17 min
AI 解读

Paul Graham 在2002年的经典文章中提出核心假设:编程语言的简洁性(succinctness)直接等价于其力量(power)。他认为高级语言的主要目标是缩小源代码,让程序员用更少的元素(element)表达更多逻辑。文章讨论了衡量程序大小的更好指标——抽象语法树节点数而非代码行数,并引用 Fred Brooks 和 Ulf Wiger 的研究支持更简洁的语言能带来更高的生产力和更少的缺陷。Graham 也辨析了可读性与简洁性的关系,认为总体可读性取决于每行可读性与行数的乘积,因此简洁性是提升可读性的关键而非对立面。文章还探讨了语言设计的限制感本质上是简洁性不足,并承认极端情况下单个程序可能过于密集,但语言层面很难“过于简洁”。本文适合编程语言设计者、对语言比较感兴趣的工程师以及关注编程效率的读者。

原文 17 分钟
原文 www.paulgraham.com ↗
§ 1

Succinctness is Power

简洁即力量

§ 2

May 2002

"The quantity of meaning compressed into a small space by algebraic signs, is another circumstance that facilitates the reasonings we are accustomed to carry on by their aid."- Charles Babbage, quoted in Iverson's Turing Award Lecture

In the discussion about issues raised by Revenge of the Nerds on the LL1 mailing list, Paul Prescod wrote something that stuck in my mind.

Python's goal is regularity and readability, not succinctness.

On the face of it, this seems a rather damning thing to claim about a programming language. As far as I can tell, succinctness = power. If so, then substituting, we get

Python's goal is regularity and readability, not power.

and this doesn't seem a tradeoff (if it is a tradeoff) that you'd want to make. It's not far from saying that Python's goal is not to be effective as a programming language.

2002 年 5 月

“代数符号将大量意义压缩在狭小空间内,这一事实也便利了我们借其进行的推理。”——查尔斯·巴贝奇,引自艾弗森图灵奖演讲

在 LL1 邮件列表关于《书呆子的复仇》所引发问题的讨论中,保罗·普雷斯科德写了一些让我印象深刻的话。

Python 的目标是规整性和可读性,而非简洁性。

从表面上看,对一个编程语言做出这样的断言颇具杀伤力。据我所知,简洁即力量。如果真是这样,代入后得到:

Python 的目标是规整性和可读性,而非力量。

这似乎不是你想要的权衡(如果这算权衡的话)。这几乎等于说 Python 的目标是作为编程语言不高效。

§ 3

Does succinctness = power? This seems to me an important question, maybe the most important question for anyone interested in language design, and one that it would be useful to confront directly. I don't feel sure yet that the answer is a simple yes, but it seems a good hypothesis to begin with.

简洁等于力量吗?在我看来,这是一个重要的问题,或许是对任何对语言设计感兴趣的人最重要的问题,而且是一个值得直接面对的问题。我还不确定答案是否简单的是,但这似乎是一个很好的起始假设。

§ 4

Hypothesis

My hypothesis is that succinctness is power, or is close enough that except in pathological examples you can treat them as identical.

It seems to me that succinctness is what programming languages are for. Computers would be just as happy to be told what to do directly in machine language. I think that the main reason we take the trouble to develop high-level languages is to get leverage, so that we can say (and more importantly, think) in 10 lines of a high-level language what would require 1000 lines of machine language. In other words, the main point of high-level languages is to make source code smaller.

If smaller source code is the purpose of high-level languages, and the power of something is how well it achieves its purpose, then the measure of the power of a programming language is how small it makes your programs.

Conversely, a language that doesn't make your programs small is doing a bad job of what programming languages are supposed to do, like a knife that doesn't cut well, or printing that's illegible.

假设

我的假设是,简洁即力量,或者说,除非在病态案例中,你可以将它们视为等同。

在我看来,简洁正是编程语言的目的。计算机乐得直接用机器语言接受指令。我们费心开发高级语言的主要原因是为了获得杠杆效应,从而可以用 10 行高级语言说出(更重要的是,思考出)原本需要 1000 行机器语言才能表达的东西。换句话说,高级语言的要点是让源代码更小。

如果更小的源代码是高级语言的目的,而某物的力量在于它实现自身目的的好坏,那么衡量编程语言力量的标准就是它让你的程序变得多小。

反之,一种不能让你的程序变小的语言,就像一把切不好的刀或模糊的印刷品一样,没有做好编程语言该做的事。

§ 5

Metrics

Small in what sense though? The most common measure of code size is lines of code. But I think that this metric is the most common because it is the easiest to measure. I don't think anyone really believes it is the true test of the length of a program. Different languages have different conventions for how much you should put on a line; in C a lot of lines have nothing on them but a delimiter or two.

Another easy test is the number of characters in a program, but this is not very good either; some languages (Perl, for example) just use shorter identifiers than others.

I think a better measure of the size of a program would be the number of elements, where an element is anything that would be a distinct node if you drew a tree representing the source code. The name of a variable or function is an element; an integer or a floating-point number is an element; a segment of literal text is an element; an element of a pattern, or a format directive, is an element; a new block is an element. There are borderline cases (is -5 two elements or one?) but I think most of them are the same for every language, so they don't affect comparisons much.

This metric needs fleshing out, and it could require interpretation in the case of specific languages, but I think it tries to measure the right thing, which is the number of parts a program has. I think the tree you'd draw in this exercise is what you have to make in your head in order to conceive of the program, and so its size is proportionate to the amount of work you have to do to write or read it.

度量

但要小到什么程度呢?最常用的代码大小度量是代码行数。但我认为这个指标之所以常用,是因为它最容易度量。我不认为有人真的相信它能真实反映程序的长度。不同语言对一行放多少内容有不同的约定;在 C 语言中,很多行只有一两个定界符。

另一个简单的度量是程序中的字符数,但这也不太好;有些语言(例如 Perl)只是使用了比其他语言更短的标识符。

我认为程序大小的更好度量是元素的数量。元素是指在表示源代码的树中会成为独立节点的任何东西。变量或函数的名字是一个元素;整数或浮点数是一个元素;一段文字是一个元素;模式的一个元素或格式化指令是一个元素;一个新块是一个元素。存在边界情况(-5 是两个元素还是一个?),但我认为大多数情况对所有语言都一样,所以不会影响比较。

这个指标需要充实,在具体语言的情况下可能需要解释,但我认为它试图度量正确的东西,即程序拥有的部分数目。我认为在这个练习中画出的树,就是你为了构想程序而必须在脑海中构建的东西,因此它的大小与你编写或阅读程序所需的工作量成正比。

§ 6

Design

This kind of metric would allow us to compare different languages, but that is not, at least for me, its main value. The main value of the succinctness test is as a guide in designing languages. The most useful comparison between languages is between two potential variants of the same language. What can I do in the language to make programs shorter?

If the conceptual load of a program is proportionate to its complexity, and a given programmer can tolerate a fixed conceptual load, then this is the same as asking, what can I do to enable programmers to get the most done? And that seems to me identical to asking, how can I design a good language?

(Incidentally, nothing makes it more patently obvious that the old chestnut "all languages are equivalent" is false than designing languages. When you are designing a new language, you're constantly comparing two languages-- the language if I did x, and if I didn't-- to decide which is better. If this were really a meaningless question, you might as well flip a coin.)

Aiming for succinctness seems a good way to find new ideas. If you can do something that makes many different programs shorter, it is probably not a coincidence: you have probably discovered a useful new abstraction. You might even be able to write a program to help by searching source code for repeated patterns. Among other languages, those with a reputation for succinctness would be the ones to look to for new ideas: Forth, Joy, Icon.

设计

这种度量可以让我们比较不同语言,但至少对我来说,这不是它的主要价值。简洁性测试的主要价值是作为设计语言的指南。语言之间最有用的比较是两种潜在变体之间的比较。我能在语言中做些什么来让程序更短?

如果程序的概念负载与其复杂度成正比,而一个程序员能承受固定的概念负载,那么这就等同于问:我怎样才能让程序员完成最多的工作?在我看来,这又等同于问:我怎样才能设计一门好语言?

(顺便说一句,没有比设计语言更能明显揭示“所有语言等价”这一老生常谈的错误了。当你设计一门新语言时,你不断在比较两种语言——如果我做了 x 的语言和如果我没做的语言——来判断哪个更好。如果这真的是一个无意义的问题,那你不如掷硬币决定。)

以简洁性为目标似乎是发现新想法的好方法。如果你能做到让许多不同程序都变短,那很可能不是巧合:你很可能发现了一个有用的新抽象。你甚至可以编写程序,通过搜索源代码中的重复模式来协助。在其他语言中,那些以简洁著称的语言值得寻找新想法:Forth、Joy、Icon。

§ 7

Comparison

The first person to write about these issues, as far as I know, was Fred Brooks in the Mythical Man Month. He wrote that programmers seemed to generate about the same amount of code per day regardless of the language. When I first read this in my early twenties, it was a big surprise to me and seemed to have huge implications. It meant that (a) the only way to get software written faster was to use a more succinct language, and (b) someone who took the trouble to do this could leave competitors who didn't in the dust.

Brooks' hypothesis, if it's true, seems to be at the very heart of hacking. In the years since, I've paid close attention to any evidence I could get on the question, from formal studies to anecdotes about individual projects. I have seen nothing to contradict him.

对比

据我所知,第一个写下这些问题的人是弗雷德·布鲁克斯,在他的《人月神话》中。他写道,程序员每天编写的代码量似乎大致相同,无论使用什么语言。我二十出头第一次读到这一点时,感到非常惊讶,并认为它有着巨大的含义。这意味着(a)更快编写软件的唯一方法是使用更简洁的语言,以及(b)愿意费心这样做的人可以让不这样做的竞争对手望尘莫及。

如果布鲁克斯的假设为真,它似乎正是黑客技术的核心。从那以后的几年里,我一直密切关注这个问题上的任何证据,从正式研究到单个项目的轶事。我没有看到任何能反驳他的东西。

§ 8

I have not yet seen evidence that seemed to me conclusive, and I don't expect to. Studies like Lutz Prechelt's comparison of programming languages, while generating the kind of results I expected, tend to use problems that are too short to be meaningful tests. A better test of a language is what happens in programs that take a month to write. And the only real test, if you believe as I do that the main purpose of a language is to be good to think in (rather than just to tell a computer what to do once you've thought of it) is what new things you can write in it. So any language comparison where you have to meet a predefined spec is testing slightly the wrong thing.

The true test of a language is how well you can discover and solve new problems, not how well you can use it to solve a problem someone else has already formulated. These two are quite different criteria. In art, mediums like embroidery and mosaic work well if you know beforehand what you want to make, but are absolutely lousy if you don't. When you want to discover the image as you make it-- as you have to do with anything as complex as an image of a person, for example-- you need to use a more fluid medium like pencil or ink wash or oil paint. And indeed, the way tapestries and mosaics are made in practice is to make a painting first, then copy it. (The word "cartoon" was originally used to describe a painting intended for this purpose).

What this means is that we are never likely to have accurate comparisons of the relative power of programming languages. We'll have precise comparisons, but not accurate ones. In particular, explicit studies for the purpose of comparing languages, because they will probably use small problems, and will necessarily use predefined problems, will tend to underestimate the power of the more powerful languages.

我还没有看到有决定性意义的证据,也不指望看到。像卢茨·普雷切特的编程语言比较这类研究,虽然产生了符合我预期的结果,但往往使用的问题太短,不足以成为有意义的测试。对语言更好的测试是那些需要花费一个月来编写的程序。而且,如果你和我一样相信语言的主要目的是便于思考(而不仅仅是想到之后告诉计算机怎么做),那么唯一的真正测试就是你能用它写出什么新东西。因此,任何需要满足预定义规范的比较都在测试稍有偏差的东西。

对语言的真正考验是你能多么好地发现和解决新问题,而不是你能用它解决别人已经提出的问题。这两者是完全不同的标准。在艺术中,像刺绣和马赛克这样的媒介,如果你事先知道想做什么,它们效果很好;但如果不知道,它们就非常糟糕。当你想在创作过程中发现图像时——例如,你必须处理像人像这样复杂的东西——你需要更流畅的媒介,如铅笔、水墨或油画。实际上,挂毯和马赛克在实践中的制作方法是先画一幅画,然后复制它。(“卡通”一词最初就是描述用于此目的的绘画。)

这意味着我们不太可能对编程语言的相对力量有准确的比较。我们会有精确的比较,但不是准确的。特别是,为了比较语言而进行的明确研究,因为它们可能使用小问题,并且必然使用预定义的问题,往往会低估更强大语言的力量。

§ 9

Reports from the field, though they will necessarily be less precise than "scientific" studies, are likely to be more meaningful. For example, Ulf Wiger of Ericsson did a study that concluded that Erlang was 4-10x more succinct than C++, and proportionately faster to develop software in:

Comparisons between Ericsson-internal development projects indicate similar line/hour productivity, including all phases of software development, rather independently of which language (Erlang, PLEX, C, C++, or Java) was used. What differentiates the different languages then becomes source code volume.

The study also deals explictly with a point that was only implicit in Brooks' book (since he measured lines of debugged code): programs written in more powerful languages tend to have fewer bugs. That becomes an end in itself, possibly more important than programmer productivity, in applications like network switches.

来自实地的报告,虽然必然不如“科学”研究精确,但可能更有意义。例如,爱立信的乌尔夫·维格进行了一项研究,结论是 Erlang 比 C++ 简洁 4-10 倍,并且软件开发速度也按比例更快:

爱立信内部开发项目之间的比较表明,包含所有软件开发阶段的行/小时生产力相似,且与使用哪种语言(Erlang、PLEX、C、C++ 或 Java)相当独立。区分不同语言的则是源代码的容量。

该研究也明确处理了布鲁克斯书中仅隐含的一点(因为他测量的是调试过的代码行数):用更强语言编写的程序往往 bug 更少。在像网络交换机这样的应用中,这本身就成为了一个目的,可能比程序员生产力更重要。

§ 10

The Taste Test

Ultimately, I think you have to go with your gut. What does it feel like to program in the language? I think the way to find (or design) the best language is to become hypersensitive to how well a language lets you think, then choose/design the language that feels best. If some language feature is awkward or restricting, don't worry, you'll know about it.

Such hypersensitivity will come at a cost. You'll find that you can't stand programming in clumsy languages. I find it unbearably restrictive to program in languages without macros, just as someone used to dynamic typing finds it unbearably restrictive to have to go back to programming in a language where you have to declare the type of every variable, and can't make a list of objects of different types.

I'm not the only one. I know many Lisp hackers that this has happened to. In fact, the most accurate measure of the relative power of programming languages might be the percentage of people who know the language who will take any job where they get to use that language, regardless of the application domain.

直觉测试

最终,我认为你必须相信自己的直觉。用某种语言编程感觉如何?我认为找到(或设计)最佳语言的方法是变得对语言让你思考的能力高度敏感,然后选择/设计感觉最好的语言。如果某个语言特性尴尬或受限,别担心,你会知道的。

这种过度敏感是有代价的。你会发现无法忍受用笨拙的语言编程。我觉得在没有宏的语言中编程极其受限,就像习惯了动态类型的人必须回到需要声明每个变量类型且不能创建不同类型对象列表的语言中编程一样。

我不是唯一有这种感觉的人。我知道许多 Lisp 黑客也有同样经历。实际上,编程语言相对力量最准确的度量可能是:懂该语言的人中,愿意接受任何能用该语言的工作(无论应用领域)的比例。

§ 11

Restrictiveness

I think most hackers know what it means for a language to feel restrictive. What's happening when you feel that? I think it's the same feeling you get when the street you want to take is blocked off, and you have to take a long detour to get where you wanted to go. There is something you want to say, and the language won't let you.

What's really going on here, I think, is that a restrictive language is one that isn't succinct enough. The problem is not simply that you can't say what you planned to. It's that the detour the language makes you take is longer. Try this thought experiment. Suppose there were some program you wanted to write, and the language wouldn't let you express it the way you planned to, but instead forced you to write the program in some other way that was shorter. For me at least, that wouldn't feel very restrictive. It would be like the street you wanted to take being blocked off, and the policeman at the intersection directing you to a shortcut instead of a detour. Great!

I think most (ninety percent?) of the feeling of restrictiveness comes from being forced to make the program you write in the language longer than one you have in your head. Restrictiveness is mostly lack of succinctness. So when a language feels restrictive, what that (mostly) means is that it isn't succinct enough, and when a language isn't succinct, it will feel restrictive.

限制感

我认为大多数黑客知道语言让人感到受限意味着什么。当你感到受限时发生了什么?我认为这就像你想走的路被封了,你不得不绕远路才能到达目的地。有些东西你想表达,但语言不允许。

我认为真正发生的,是受限的语言不够简洁。问题不仅仅是你不能按计划说,而是语言让你走的绕路更长。试试这个思想实验:假设你想写某个程序,语言不让你按计划的方式表达,但迫使你以另一种更短的方式写。至少对我来说,这不会感觉很受限。这就像你想走的路被封了,但路口的警察指引你走捷径而不是绕路。太棒了!

我认为大部分(百分之九十?)的限制感来自于被迫使你在语言中写的程序比你脑海中的程序更长。限制感主要是缺乏简洁性。所以当一种语言让人感到受限时,那(主要)意味着它不够简洁,而语言不简洁时,就会让人感到受限。

§ 12

Readability

The quote I began with mentions two other qualities, regularity and readability. I'm not sure what regularity is, or what advantage, if any, code that is regular and readable has over code that is merely readable. But I think I know what is meant by readability, and I think it is also related to succinctness.

We have to be careful here to distinguish between the readability of an individual line of code and the readability of the whole program. It's the second that matters. I agree that a line of Basic is likely to be more readable than a line of Lisp. But a program written in Basic is is going to have more lines than the same program written in Lisp (especially once you cross over into Greenspunland). The total effort of reading the Basic program will surely be greater.

total effort = effort per line x number of lines

I'm not as sure that readability is directly proportionate to succinctness as I am that power is, but certainly succinctness is a factor (in the mathematical sense; see equation above) in readability. So it may not even be meaningful to say that the goal of a language is readability, not succinctness; it could be like saying the goal was readability, not readability.

可读性

我开头引用的那句话提到了另外两个品质:规整性和可读性。我不确定规整性是什么,或者规整可读的代码相比仅仅可读的代码有什么优势。但我想我知道可读性是什么意思,而且我认为它也与简洁性相关。

这里我们要小心区分单行代码的可读性和整个程序的可读性。重要的是后者。我同意一行 Basic 可能比一行 Lisp 更易读。但用 Basic 写的程序会比用 Lisp 写的同一程序有更多行(尤其是当你进入格林斯潘之地时)。阅读 Basic 程序的总工作量肯定更大。

总工作量 = 每行工作量 × 行数

我不像确信力量那样确信可读性与简洁性直接成正比,但毫无疑问简洁性是可读性的一个因素(在数学意义上,见上式)。所以,说语言的目标是可读性而非简洁性,可能根本没有意义;这就像说目标是可读性,而不是可读性。

§ 13

What readability-per-line does mean, to the user encountering the language for the first time, is that source code will look unthreatening. So readability-per-line could be a good marketing decision, even if it is a bad design decision. It's isomorphic to the very successful technique of letting people pay in installments: instead of frightening them with a high upfront price, you tell them the low monthly payment. Installment plans are a net lose for the buyer, though, as mere readability-per-line probably is for the programmer. The buyer is going to make a lot of those low, low payments; and the programmer is going to read a lot of those individually readable lines.

This tradeoff predates programming languages. If you're used to reading novels and newspaper articles, your first experience of reading a math paper can be dismaying. It could take half an hour to read a single page. And yet, I am pretty sure that the notation is not the problem, even though it may feel like it is. The math paper is hard to read because the ideas are hard. If you expressed the same ideas in prose (as mathematicians had to do before they evolved succinct notations), they wouldn't be any easier to read, because the paper would grow to the size of a book.

单行可读性,对初次接触语言的用户来说,意味着源代码看起来不吓人。因此,单行可读性可能是一个好的营销决策,即使它是一个糟糕的设计决策。这类似于非常成功的分期付款技巧:不用高昂的前期价格吓跑他们,而是告诉他们低月供。然而分期付款对买家来说是净亏损的,正如单纯的单行可读性对程序员很可能也是如此。买家会支付很多很多低月供;程序员也会阅读很多很多单独可读的行。

这种权衡在编程语言之前就已存在。如果你习惯读小说和报纸文章,第一次读数学论文可能会沮丧。可能花半小时才能读一页。但我很确定符号不是问题,尽管感觉可能是。数学论文难读是因为想法难。如果你用散文表达同样的想法(就像数学家在发展出简洁符号之前不得不做的那样),它们不会更容易读,因为论文会膨胀到一本书的篇幅。

§ 14

To What Extent?

A number of people have rejected the idea that succinctness = power. I think it would be more useful, instead of simply arguing that they are the same or aren't, to ask: to what extent does succinctness = power? Because clearly succinctness is a large part of what higher-level languages are for. If it is not all they're for, then what else are they for, and how important, relatively, are these other functions?

I'm not proposing this just to make the debate more civilized. I really want to know the answer. When, if ever, is a language too succinct for its own good?

The hypothesis I began with was that, except in pathological examples, I thought succinctness could be considered identical with power. What I meant was that in any language anyone would design, they would be identical, but that if someone wanted to design a language explicitly to disprove this hypothesis, they could probably do it. I'm not even sure of that, actually.

到什么程度?

许多人拒绝接受简洁即力量的观点。我认为与其简单地争论它们是否等同,不如问:简洁在多大程度上等于力量?因为很明显,简洁是高级语言目的的一大部分。如果不是全部,那它们还有什么其他目的,并且这些其他功能相对有多重要?

我提这个问题不只是为了让讨论更文明。我真的想知道答案。如果存在这种情况,一种语言什么时候会过于简洁,反受其害?

我开始的假设是,除了病态案例,我认为简洁可以视为与力量等同。我的意思是,在任何人会设计的语言中,它们会是等同的,但如果有人想专门设计一种语言来反驳这个假设,他们可能做得到。实际上我对此都不太确定。

§ 15

Languages, not Programs

We should be clear that we are talking about the succinctness of languages, not of individual programs. It certainly is possible for individual programs to be written too densely.

I wrote about this in On Lisp. A complex macro may have to save many times its own length to be justified. If writing some hairy macro could save you ten lines of code every time you use it, and the macro is itself ten lines of code, then you get a net saving in lines if you use it more than once. But that could still be a bad move, because macro definitions are harder to read than ordinary code. You might have to use the macro ten or twenty times before it yielded a net improvement in readability.

I'm sure every language has such tradeoffs (though I suspect the stakes get higher as the language gets more powerful). Every programmer must have seen code that some clever person has made marginally shorter by using dubious programming tricks.

So there is no argument about that-- at least, not from me. Individual programs can certainly be too succinct for their own good. The question is, can a language be? Can a language compel programmers to write code that's short (in elements) at the expense of overall readability?

One reason it's hard to imagine a language being too succinct is that if there were some excessively compact way to phrase something, there would probably also be a longer way. For example, if you felt Lisp programs using a lot of macros or higher-order functions were too dense, you could, if you preferred, write code that was isomorphic to Pascal. If you don't want to express factorial in Arc as a call to a higher-order function

(rec zero 1 * 1-)

you can also write out a recursive definition:

(rfn fact (x) (if (zero x) 1 (* x (fact (1- x)))))

Though I can't off the top of my head think of any examples, I am interested in the question of whether a language could be too succinct. Are there languages that force you to write code in a way that is crabbed and incomprehensible? If anyone has examples, I would be very interested to see them.

(Reminder: What I'm looking for are programs that are very dense according to the metric of "elements" sketched above, not merely programs that are short because delimiters can be omitted and everything has a one-character name.)

语言,而非程序

我们应该清楚,我们讨论的是语言的简洁性,而不是单个程序的简洁性。单个程序确实可能写得过于密集。

我在《论 Lisp》中写过这个。一个复杂的宏可能需要节省自身长度许多倍才能合理。如果写某个棘手的宏每次使用能节省十行代码,而宏本身是十行代码,那么如果使用超过一次,你在行数上就有净节省。但这仍然可能是一个糟糕的举动,因为宏定义比普通代码更难读。你可能需要使用该宏十次或二十次,它才能在可读性上产生净改善。

我确信每种语言都有这样的权衡(尽管我怀疑语言越强大,赌注越高)。每个程序员一定见过某个聪明人用可疑的编程技巧让代码勉强更短。

所以对此没有争议——至少我没有。单个程序确实可能过于简洁,反受其害。问题是,语言本身会吗?一种语言能否迫使程序员编写(按元素)很短但牺牲整体可读性的代码?

很难想象一种语言过于简洁的一个原因是,如果存在某种过于紧凑的表达方式,很可能也存在更长的表达方式。例如,如果你觉得大量使用宏或高阶函数的 Lisp 程序过于密集,你可以选择编写与 Pascal 同构的代码。如果你不想将 Arc 中的阶乘表达为高阶函数调用:

(rec zero 1 * 1-)

你也可以写出递归定义:

(rfn fact (x) (if (zero x) 1 (* x (fact (1- x)))))

虽然我一时想不出任何例子,但我对语言是否能过于简洁的问题很感兴趣。是否存在迫使你以生涩难懂的方式编写代码的语言?如果有人有例子,我很想看到。

(提醒:我正在寻找的是根据上面概述的“元素”度量非常密集的程序,而不仅仅是那些因为可以省略定界符且所有标识符都是单个字符而很简短的程序。)

打开原文 ↗