关于syntactic sugar的译法

Posted by admin | 翻译, 原创 | 星期三 20 8月 2008 10:11 上午

根据thefreedictionary.com上的解释, syntactic sugar,指的是“语法中的糖分”,但此术语的中心词是“语法”,所以可以说成”含糖的语法”(也可以与下文中的“富糖”、“脱糖”对应)。另外,如果出现频率不高的话,也可以译为“语法糖衣”。

[译文]
含糖语法,是由Peter J. Landin创造的一个术语,指的是为一门计算机语言的语法中添加的附加物或附加成分,它不会影响语言的功能,但却能使人类使用起该语言来”更甜美”一些。含糖语法为编程人员(对计算机规范语言来说,是设计人员)提供了一种编写程序(编写规范)的替代方式,这种方式更具有实用性、更有助于形成较好的程序设计风格,或者使代码读起来更自然。但是,它不会影响形式上的可表达性,也不会让语言拥有某种新功能。

很容易用某种更简单的”核心”语法,将含糖语法转换(“脱糖”)为一个程序(规范)。以Landin为例,其核心是通过一系列操作(如赋值)浓缩成的λ演算。受Landin的启发,一些后来的编程语言,像ML和Scheme,都明确地设计为一种基于要素构件的语言核心。为方便起见,高级特性经过”脱糖”或降解,可以转换为其子集。事实上,这正是在原语基础上构建起来的通常的数学实践。然而,许多现代的、”富糖”型的语言(例如C#)则无法脱糖。但之所以它们的特性仍被视为”含糖”,是因为存在于先驱语言(例如C)中的原语,足以重新创建这些语言。

[原文]
Syntactic sugar is a term coined by Peter J. Landin for additions to the syntax of a computer language that do not affect its functionality but make it “sweeter” for humans to use. Syntactic sugar gives the programmer (designer, in the case of specification computer languages) an alternative way of coding (specifying) that is often more practical, more conducive to a better programming style, or more natural to read. However, it does not typically affect the expressiveness of the formalism or permit the language to do something
new.

Syntactic sugar can often be easily translated (”desugared”) to produce a program (specification) in some simpler “core” syntax. In Landin’s case, the core was a lambda calculus enriched with a few operations, such as assignment. Following Landin’s insights, some later programming languages, such as ML and Scheme, were explicitly designed as a language core of essential constructs. The convenient, higher-level features could be desugared and decomposed into that subset. This is, in fact, the usual mathematical practice of building up from primitives. However many modern, “sugar-rich” languages (such as C#) cannot be desugared. Still, their features may be considered “sugar” because primitives exist in predecessor languages (such as C) to fully recreate them.

4 条评论 »

  1. 评论 作者 Yurii — 2008-08-26 @ 6:37 上午

    这个我一般翻译为“语法诀窍”,sweeter翻译为“更顺手”
    另有一点建议供参考:
    Syntactic sugar gives the programmer (designer, in the case of specification computer languages) an alternative way of coding (specifying) that is often more practical, more conducive to a better programming style, or more natural to read
    以本人愚见,这里括号内的意思似乎是说,语法诀窍能够为制定语言规范的人提供便利,定出替代方式,它们更实用、更易于……

  2. 评论 作者 admin — 2008-08-26 @ 9:01 上午

    还是“更实用、更易于”像中国话,呵呵~
    这两天正好遇到一个Syntactic sugar的上下文——“NodeList是Array的子类,在Base中定义,并为连缀其他操作提供了语法糖衣(syntactic sugar)……”。也就是说,NodeList扩展了Array,同时又在Array基础上添加了很多附加功能——比如“连缀其他操作”。而这些附加功能就是所谓的“syntactic sugar”。(参见:Dojo精解(一)

  3. 评论 作者 zsuxqm — 2008-08-28 @ 9:59 上午

    enriched 翻译成“浓缩”似乎和原意相反了,而且,“赋值”是不能加到lambda里的。我觉得翻译成:
    其核心是λ演算,外加少数操作,比如赋值。
    这样比较好些

  4. 评论 作者 admin — 2008-08-28 @ 8:59 下午

    言之有理。

对这篇文章的评论的 RSS 聚合。 TrackBack URI

发表您的评论

验证码  If you cannot see the CheckCode image,please refresh the page again!