Difference between revisions of "Syntactic sugar"
Karl Jones (Talk | contribs) (etc) |
Karl Jones (Talk | contribs) |
||
| Line 29: | Line 29: | ||
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. | 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. | ||
| − | == Language processors == | + | == Language processors and desugaring == |
Language processors, including [[Compiler|compilers]], static analyzers, and the like, often expand sugared constructs into more fundamental constructs before processing, a process sometimes called "desugaring". | Language processors, including [[Compiler|compilers]], static analyzers, and the like, often expand sugared constructs into more fundamental constructs before processing, a process sometimes called "desugaring". | ||
| Line 41: | Line 41: | ||
== External links == | == External links == | ||
| − | * [ ] @ Wikipedia | + | * [https://en.wikipedia.org/wiki/Syntactic_sugar Syntactic sugar] @ Wikipedia |
| + | |||
| + | [[Category:Computation]] | ||
| + | [[Category:Computer programming]] | ||
| + | [[Category:Computer science]] | ||
Latest revision as of 10:08, 18 April 2016
In computer science, syntactic sugar is syntax within a programming language that is designed to make things easier to read or to express.
Contents
Description
Syntactic sugar makes the language "sweeter" for human use: things can be expressed more clearly, more concisely, or in an alternative style that some may prefer.
Examples
For example, many programming languages provide special syntax for referencing and updating array elements.
Abstractly, an array reference is a procedure of two arguments: an array and a subscript vector, which could be expressed as:
get_array(Array, vector(i,j))
Instead, many languages provide syntax like:
Array[i,j]
Similarly an array element update is a procedure of three arguments, something like:
set_array(Array, vector(i,j), value)
Many languages provide syntax like:
Array[i,j] = value
Functionality and expressive power will remain the same
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.
Language processors and desugaring
Language processors, including compilers, static analyzers, and the like, often expand sugared constructs into more fundamental constructs before processing, a process sometimes called "desugaring".
See also
External links
- Syntactic sugar @ Wikipedia