Bespoke: A Programming Language for People Who Say Please

Bespoke: A Programming Language for People Who Say Please

Bespoke:一门为懂得说“请”的人设计的编程语言

Programming has developed an unfortunate tone. We kill processes, abort transactions, throw exceptions, break out of loops, and execute instructions. We acquire locks without asking, mutate values without apologising, and order the machine to return as though it were a Labrador. 编程语言已经形成了一种令人遗憾的语调。我们“杀死”(kill)进程、“中止”(abort)事务、“抛出”(throw)异常、“跳出”(break)循环,并“执行”(execute)指令。我们不经询问就获取锁,不道歉就修改数值,并像对待拉布拉多犬一样命令机器返回结果。

Even the gentler languages expect us to address the runtime in a sequence of terse imperatives: let carriageCount = 0; carriageCount = 42; console.log(carriageCount); No salutation. No explanation. Not so much as a much obliged. This will not do. 即使是那些更温和的语言,也要求我们用一系列简短的祈使句来处理运行时:let carriageCount = 0; carriageCount = 42; console.log(carriageCount); 没有问候,没有解释,甚至连一句“多谢”都没有。这可不行。

I therefore propose Bespoke, a statically typed and uncompromisingly civilised programming language for developers who believe that machine execution should never come at the expense of good manners. Informally it is known as The Queen’s Code: Victoria’s, naturally; the etiquette committee has yet to approve the twentieth century. 因此,我提议推出 Bespoke,这是一门静态类型且极其文明的编程语言,专为那些认为机器执行不应以牺牲礼仪为代价的开发者而设计。非正式地,它被称为“女王的代码”(The Queen’s Code):当然是指维多利亚女王的;礼仪委员会至今尚未批准二十世纪的礼仪。

Source files use the .charming extension, and the compiler reserves the right to be disappointed in you. The implementation is, at present, somewhat less advanced than the etiquette manual. This is entirely appropriate: one does not rush a formal introduction. (No relation to Josiah Winslow’s Bespoke, the 2025 esolang based on Poetic that encodes instructions through word lengths. We regret the social inconvenience.) 源文件使用 .charming 扩展名,编译器保留对你感到失望的权利。目前的实现进度比礼仪手册要滞后一些。这非常恰当:人们不会仓促地进行正式介绍。(此语言与 Josiah Winslow 在 2025 年推出的基于 Poetic、通过词长编码指令的深奥语言 Bespoke 无关。我们对由此造成的社交不便深表歉意。)

The Compiler Is Not Your Servant

编译器不是你的仆人

Bespoke begins with one simple observation: the compiler is an esteemed collaborator, not a menial functionary. It will not accept an unadorned command. Every request must open with an appropriate form of address, state its purpose courteously, and conclude with an approved acknowledgement. Bespoke 从一个简单的观察开始:编译器是一位受人尊敬的合作者,而不是卑微的办事员。它不会接受未经修饰的命令。每一个请求都必须以适当的称呼开头,礼貌地陈述目的,并以认可的致谢语结束。

Control-flow blocks supply their own ceremonial openings and closings. Allocations and updates are addressed to the Compiler; terminal output, including standard error, to the Output Console; filesystem operations and runtime services to the Host Environment. Shared objects and worker threads receive their correspondence directly. One does not ask the groundskeeper to announce the guests. 控制流块提供其专属的仪式性开头和结尾。内存分配和更新需向“编译器”提出;终端输出(包括标准错误)需向“输出控制台”提出;文件系统操作和运行时服务需向“宿主环境”提出。共享对象和工作线程则直接接收信函。人们不会让园丁去通报宾客。

Declaring an integer consequently looks like this: 因此,声明一个整数看起来是这样的:

Dear Compiler, Would you be so exceptionally kind as to allocate a slot for An Integer Number known henceforth as carriageCount, initialised with the value 0? Thank you ever so much.

亲爱的编译器, 您能否大发慈悲,为今后称为 carriageCount 的“整数”分配一个槽位,并将其初始化为 0? 万分感谢。

This is more verbose than int carriageCount = 0, but considerably less likely to create a hostile work environment. Punctuation is grammatical rather than ornamental. Statements end with full stops, inquiries with question marks, and a block with a suitable sign-off. Semicolons are rejected as the conversational equivalent of slamming a door. 这比 int carriageCount = 0 要冗长得多,但不太可能造成敌对的工作环境。标点符号是语法的一部分,而非装饰。语句以句号结尾,询问以问号结尾,代码块则以合适的落款结束。分号被拒绝使用,因为在对话中,它等同于摔门而去。

A Type System of Proper Breeding

讲究门第的类型系统

Bespoke is statically typed because allowing a value to pretend to be something it is not would be dishonest. It is also nominally typed because introductions matter. Types are written in full; clipped little vulgarisms such as int, char, and bool have no place in polite source code. Bespoke 是静态类型的,因为允许一个值伪装成它本不是的东西是不诚实的。它也是名义类型的,因为介绍很重要。类型必须完整书写;像 intcharbool 这样简短粗俗的词汇在礼貌的源代码中没有立足之地。

Bespoke typeLess refined equivalentExample
An Integer Number64-bit signed integer42
A Rational FractionExact ratio of arbitrary-precision integers355/113
A Textual PassageUTF-8 string”Good day to you.”
An Individual CharacterUnicode scalar value’£‘
A Truth ValueBooleanQuite True
A Distinguished ColourFirst-class colourColour.BritishRacingGreen
A Regrettable CircumstanceExceptionLedgerMissingMisfortune
Bespoke 类型粗糙的等价物示例
An Integer Number (整数)64位有符号整数42
A Rational Fraction (有理分数)任意精度整数的精确比率355/113
A Textual Passage (文本段落)UTF-8 字符串”Good day to you.”
An Individual Character (单个字符)Unicode 标量值’£‘
A Truth Value (真值)布尔值Quite True (确实如此)
A Distinguished Colour (尊贵的颜色)一等颜色Colour.BritishRacingGreen
A Regrettable Circumstance (遗憾的情况)异常LedgerMissingMisfortune

British orthography is enforced during lexical analysis. Colour is the namespace for values of A Distinguished Colour. Color is evidence that the source has arrived without a proper education. Initialisation has an s, centre is spelled correctly, and an optimiser may remove redundant work but will never optimize it. 词法分析期间会强制执行英式拼写。ColourA Distinguished Colour 类型值的命名空间。Color 是源代码未经良好教育的证据。Initialisation 必须带 scentre 必须拼写正确,优化器(optimiser)可以移除冗余工作,但绝不会 optimize(美式拼写)它。

There are precisely two truth literals: Quite True and Patently False. A third, implementation-defined state named Perhaps, Though I Should Not Like to Presume was considered for database work and rejected as insufficiently deterministic. 真值字面量只有两个:Quite True(确实如此)和 Patently False(显然错误)。第三种由实现定义的名为 Perhaps, Though I Should Not Like to Presume(也许吧,虽然我不愿妄下定论)的状态曾被考虑用于数据库工作,但因确定性不足而被拒绝。

Mutation Requires an Apology

修改需要道歉

Functional programmers are correct that mutable state is troublesome, but prohibition feels rather severe. Bespoke permits mutation provided that the programmer acknowledges the inconvenience: 函数式程序员认为可变状态很麻烦是对的,但完全禁止显得过于严苛。Bespoke 允许修改,前提是程序员要承认这种不便:

Dear Compiler, If it causes you no undue hardship, might we trouble you to update the value of carriageCount to 42? Much obliged.

亲爱的编译器, 如果不会给您造成过多的负担,能否麻烦您将 carriageCount 的值更新为 42? 不胜感激。

The compiler is under no obligation to accept a mutation phrased as an order. carriageCount = 42 produces diagnostic B-101, Blunt Imperative, and compilation is suspended until the developer has reflected upon their conduct. 编译器没有义务接受以命令形式表达的修改请求。carriageCount = 42 会产生 B-101 号诊断信息“生硬的祈使句”,编译将暂停,直到开发者反思自己的行为。

Memory management follows the same principle. Automatic garbage collection is not assumed; one formally engages the groundskeeper: 内存管理遵循同样的原则。不假设存在自动垃圾回收;人们需要正式地聘请园丁:

Dear Host Environment, Pardon the intrusion, but might the groundskeeper occasionally tidy away any allocations no longer reachable by the programme, at your leisure? Yours gratefully.

亲爱的宿主环境, 冒昧打扰,能否请园丁在您方便时,偶尔清理一下程序不再可达的内存分配? 感激不尽。

Manual deallocation is available for performance-sensitive correspondence, although discarding an allocation without a sincere apology is undefined behaviour and, worse, common. 对于性能敏感的通信,可以使用手动释放内存,尽管在没有真诚道歉的情况下丢弃分配是未定义行为,而且更糟糕的是,这很常见。

Control Flow by Deliberation

审慎的控制流

An if statement is an accusation: this condition is true, now do as I say. Bespoke instead places a hypothetical question before the court. if 语句是一种指控:这个条件是真的,现在照我说的做。而 Bespoke 则是在法庭上提出一个假设性问题。

Should it please the court to consider whether carriageCount is strictly greater than 10, Dear Output Console, Kindly convey to the standard stream the Textual Passage “Capital progress, indeed!”. Thank you kindly. Or, should the contrary prove true, Dear Output Console, Kindly convey to the standard stream the Textual Passage “A modest showing, regrettably.”. Thank you kindly. Thus concludes the matter.

若法庭乐意审议 carriageCount 是否严格大于 10, 亲爱的输出控制台, 请向标准流传达文本段落“确实是巨大的进步!”。 谢谢。 或者,如果事实恰恰相反, 亲爱的输出控制台, 请向标准流传达文本段落“遗憾的是,表现平平。”。 谢谢。 此事至此结束。

For a given truth value, the choice of branch is deterministic. The court is ceremonial and cannot be lobbied by either side. 对于给定的真值,分支的选择是确定性的。法庭是仪式性的,不能被任何一方游说。