Syntactic sugar

Syntactic sugar

Syntactic sugar is a computer science term that refers to syntax within a programming language that is designed to make things easier to read or to express.

It makes the language "sweeter" for humans to use: things can be expressed more clearly, more concisely, or in an alternative style that some may prefer.

Specifically, a construct in a language is called syntactic sugar if it can be removed from the language without any effect on what the language can do: functionality and expressive power will remain the same. All applications of the construct can be systematically replaced with equivalents that do not use it. For instance, in imperative programming languages, for loops can be systematically replaced with while loops, which in turn can be systematically replaced with gotos.

More generally, the term is used to characterize syntax as being designed for ease of expression. For instance, in C#, the property construct may be called syntactic sugar: it is roughly, but not exactly equivalent to a getter-setter pair of functions. Even more broadly, high-level programming languages have been called[by whom?] "machine code with a lot of syntactic sugar."

Contents

Origins

The term syntactic sugar was coined by Peter J. Landin in 1964 to describe the surface syntax of a programming language which was defined semantically in terms of the applicative expressions of lambda calculus.[1]

Later programming languages, such as ML and Scheme, extended the term to refer to syntax within a language which could be defined in terms of a language core of essential constructs; the convenient, higher-level features could be "desugared" and decomposed into that subset.[citation needed] This is, in fact, the usual mathematical practice of building up from primitives.

Criticism

Some programmers feel that these syntax usability features are either unimportant or outright frivolous. For example, Alan Perlis once quipped, in a reference to bracket-delimited languages, that "syntactic sugar causes cancer of the semicolon". (See Epigrams on Programming.)

Derivative terms

Syntactic salt

The metaphor has been extended by coining the term syntactic salt, which indicates a feature designed to make it harder to write bad code. Specifically, syntactic salt is a hoop programmers must jump through just to prove that they know what's going on, rather than to express a program action. For example, Java will not allow you to declare a variable as an int and then assign it a float or double value, while C and C++ will automatically truncate any floats assigned to an int.

Syntactic saccharin

Another extension is syntactic saccharin, meaning gratuitous syntax that does not actually make programming easier.[2]

Notes and references

  1. ^ Peter J. Landin, "The mechanical evaluation of expressions", Computer Journal 6:4: 308-320 (1964) doi:10.1093/comjnl/6.4.308
  2. ^ The Jargon File v4.4.7: "syntactic sugar"
  • Landin, Peter J.; A Correspondence Between ALGOL 60 and Church's Lambda-Notation: Parts I and II, Communications of the ACM, 8(2.3):89-101, 158-165 (February and March 1965)
  • Landin, Peter J.; Programming Without Imperatives - An Example, Technical report, UNIVAC Systems Programming Research, March 1965
  • Landin, Peter J.; Getting Rid of Labels, Technical report, UNIVAC Systems Programming Research, July 1965
  • Landin, Peter J.; A Generalization of Jumps and Labels, Report, UNIVAC Systems Programming Research, August 1965, reprinted in Higher-Order and Symbolic Computation, 11, pp. 125–143 (1998)

This article was originally based on material from the Free On-line Dictionary of Computing, which is licensed under the GFDL.


Wikimedia Foundation. 2010.

Игры ⚽ Нужно сделать НИР?

Look at other dictionaries:

  • Syntactic Sugar — Syntaktischer Zucker sind Syntaxerweiterungen in Programmiersprachen, welche der Vereinfachung von Schreibweisen dienen. Diese Erweiterungen sind alternative Schreibweisen, welche aber nicht die Ausdrucksstärke und Funktionalität der… …   Deutsch Wikipedia

  • syntactic sugar — noun Additions to a computer language that make code easier for humans to read or write, but that do not change the functionality or expressiveness of the language …   Wiktionary

  • Sugar (disambiguation) — Sugar is a common food ingredient.Sugar can also refer to:Culture* A popular term of endearment. * A popular stripper name.BiochemistryAny of the simpler forms of carbohydrates, including: * monosaccharides (simple sugars) such as glucose,… …   Wikipedia

  • Syntactic Salt — Syntaktischer Zucker sind Syntaxerweiterungen in Programmiersprachen, welche der Vereinfachung von Schreibweisen dienen. Diese Erweiterungen sind alternative Schreibweisen, welche aber nicht die Ausdrucksstärke und Funktionalität der… …   Deutsch Wikipedia

  • Comparison of programming paradigms — Programming paradigms Agent oriented Automata based Component based Flow based Pipelined Concatenative Concurrent computin …   Wikipedia

  • Oz (programming language) — Oz Paradigm(s) multi paradigm: logic, functional, imperative, object oriented, constraint, distributed, concurrent Appeared in 1991 Designed by Gert Smolka, his students Developer Mozart …   Wikipedia

  • C Sharp syntax — The correct title of this article is C# syntax. The substitution or omission of the # sign is because of technical restrictions. Main article: C Sharp (programming language) This article describes the syntax of the C# programming language. The… …   Wikipedia

  • Monad (functional programming) — In functional programming, a monad is a programming structure that represents computations. Monads are a kind of abstract data type constructor that encapsulate program logic instead of data in the domain model. A defined monad allows the… …   Wikipedia

  • Comparison of C Sharp and Java — The correct title of this article is Comparison of C# and Java. The substitution or omission of the # sign is because of technical restrictions. Programming language comparisons General comparison Basic syntax Basic instructions …   Wikipedia

  • Erlang (programming language) — Erlang Paradigm(s) multi paradigm: concurrent, functional Appeared in 1986 Designed by Ericsson …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”