简单之美(The Beauty of Simplicity)

本文深入探讨了代码的美学与艺术性,强调了布局、命名等表面因素之外的深层次语义特性,如抽象的明智使用、类层次的优雅组建、参数列表的有序排列等,这些特征体现了代码的深层美感,远超表面形式。文中引用了Ralph Waldo Emerson的话,将其观点与软件科学中的艺术性相联系,并提出了对代码艺术性的追求标准。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

      As an admirer of the “artistic flare, nuanced style, and technical prowess thatseparates good code from great code” explored by Robert Green and Henry Ledgardin their article “Coding Guidelines: Finding the Art in the Science” (Dec. 2011),I was disappointed by the authors’ emphasis on “alignment, naming, use of whitespace, use of context, syntax highlighting, and IDE choice.” As effective asthese aspects of beautiful code may be, they are at best only skin deep.

       我对“艺术的闪耀,有细微差别的风格和将好的代码与卓越的代码区分开来的技术能力”敬佩至极,而在文章“编程指南:在科学中寻找艺术”(2011年12月)中,Robert Green和Henry Ledgard两位作者对之进行了探索。令我感到失望的是,作者强调了“对齐,命名,空格的使用,上下文的使用,句法规则的重要性,以及IDE的选择”。对于优美的代码来说,这些方面固然重要,但它们最多只是表面上很肤浅的东西。

 

       Beautymay indeed be in the eye of the beholder, but there is a more compelling beautyin the deeper semantic properties of code than layout and naming. I alsoinclude judicious use of abstraction, deftly balancing precision andgenerality; elegant structuring of class hierarchies, carefully trading betweenbreadth and depth; artful ordering of parameter lists, neatly supporting commoncases of partial application; and efficient reuse of library code, leveragingexisting definitions with minimum effort. These are subjective characteristics,beyond the reach of objective scientific analysis—matters of taste not offact—so represent aspects of the art rather than the science of software.

       虽然实际上只有旁观者才可能看到优美性,但相对于布局和命名来说,在更深层次的语义特性中有更具说服力的优美。这些更深层次的东西包括了抽象的明智使用,熟练的平衡精度和一般性;类层次的优雅组建,宽度与深度之间的合理折中;参数列表的艺术式排序,部分应用的共同事例的恰当支持;以及库代码的高效重复利用,用最小代价来改变当前定义。这些都是主观的特性,而非客观的科学分析——是味觉,而非事实的问题——因此代表了艺术方面,而非软件科学方面。

 

       Formalizingsuch semantic properties is more difficult than establishing uniform codingconventions; we programmers spend our professional lifetimes honing our writingskills, not unlike novelists and journalists. Indeed, the great Americanessayist Ralph Waldo Emerson (1803–1882) anticipated the art in the science ofsoftware like this: “We ascribe beauty to that which is simple; which has nosuperfluous parts; which exactly answers its end; which stands related to allthings; which is the mean of many extremes.” It is to this standard I aspire.

        要规范这些语义特性比建立统一的编程规则更难;我们程序员用整个职业生涯来磨练我们的写作水平,这与小说家和记者没有什么两样。事实上,美国最伟大的作家Ralph Waldo Emerson(1803–1882)像这样预言软件科学中的艺术:“我们将优美归结为简单的东西,它没有多余的部分,它精确地道出了其目的,它代表了相关的所有事物,它是许多极端情况的折中。”我崇拜的是这个标准。

 

Jeremy Gibbons, Oxford,U.K.

 

 

参考文献

The Beauty of Simplicity, Communicationsof the ACM, vol. 55, no. 4, April 2012.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值