MarketSyntactic sugar
Company Profile

Syntactic sugar

In computer science, syntactic sugar is syntax within a programming language that is designed to make things easier to read or to express. It makes the language "sweeter" for human use: things can be expressed more clearly, more concisely, or in an alternative style that some may prefer. Syntactic sugar is usually a shorthand for a common operation that could also be expressed in an alternate, more verbose, form: The programmer has a choice of whether to use the shorter form or the longer form, but will usually use the shorter form since it is shorter and easier to type and read.

Origins
The term syntactic sugar was coined by Peter J. Landin in 1964 to describe the surface syntax of a simple ALGOL-like programming language which was defined semantically in terms of the applicative expressions of lambda calculus, centered on lexically replacing λ with "where". Later programming languages, such as CLU, 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. This is, in fact, the usual mathematical practice of building up from primitives. Building on Landin's distinction between essential language constructs and syntactic sugar, in 1991, Matthias Felleisen proposed a codification of "expressive power" to align with "widely held beliefs" in the literature. He defined "more expressive" to mean that without the language constructs in question, a program would have to be completely reorganized. == Notable examples ==
Notable examples
• In COBOL, many of the intermediate keywords are syntactic sugar that may optionally be omitted. For example, the sentence MOVE A B. and the sentence MOVE A TO B. perform exactly the same function, but the second makes the action to be performed clearer. • In Perl, {{code|unless (condition) {...}|perl}} is syntactic sugar for {{code|if (not condition) {...}|perl}}. Additionally, any statement can be followed by a condition, so is equivalent to {{code|if (condition) {...}|perl}}, but the former is more naturally formatted on a single line. • In the C language, the a[i] notation is syntactic sugar for *(a + i). Likewise, the a->x notation is syntactic sugar for accessing members using the dereference operator (*a).x. • The using statement in C# ensures that certain objects are disposed of correctly. The compiler expands the statement into a try-finally block. • C++ and C from C23 onwards allow auto x = expr as a shorthand for decltype(expr) x = expr in C++ or typeof(expr) x = expr in C. • Python list comprehensions (such as for a list of squares) and decorators (such as @staticmethod). • In Haskell, a string, denoted in quotation marks, is semantically equivalent to a list of characters. An optional language extension OverloadedStrings allows string literals to produce other types of values, such as Text, as well. • In the tidyverse collection of R packages, the pipe, denoted by %>%, declares that the data (or output of the function) preceding the pipe will serve as the first argument for the function following the pipe. So, x %>% f(y) is equivalent to f(x,y). • In SQL, a mere JOIN is equivalent to an INNER JOIN, the latter clarifying that the join statement is specifically an inner join operation as opposed to an outer join operation. Likewise, one may omit the OUTER from the LEFT OUTER JOIN, RIGHT OUTER JOIN and FULL OUTER JOIN. • Extension method in OOP languages in the form of myObject.myMethod(parameter1, parameter2, parameter3) is syntactic sugar for calling a global function as myMethod(myObject, parameter1, parameter2, parameter3). The reference to the object is passed as a hidden argument, usually accessible from within the method as this. • A parameter called by reference is syntactic sugar for technically passing a pointer as the parameter, but syntactically handling it as the variable itself, to avoid constant pointer de-referencing in the code inside the function. • Various languages offer import statements to allow adding symbols from another namespace into the current scope. • In C++, a using statement is such an example for importing a single symbol into scope, while a using namespace namespace imports all symbols from that namespace into scope. • In C#, a using statement adds all symbols from a namespace into scope. • In Java, an import is such an example. For example import javax.swing.*; allows the programmer to reference a Swing object such as javax.swing.JButton using just the name JButton. • In Python, a from import statement imports a single symbol into scope, while a from import * statement imports all symbols from that namespace into scope. • In Rust, a use statement is used for importing symbols into scope. • In JavaScript, if the key and value are the same in an object, you have the option to write it just once. For example, {name: name} is equivalent to {name}. This is called the Shorthand Property. • In the ES6 version of JavaScript, arrow functions have a short form (x) => x + 1, which is equivalent to the longer form {{code|2=javascript|1=(x) => { return x + 1; } }}. • In Scala, triple question marks (???) is equivalent to . This is useful to mark a place for code that has not yet been written. == Criticism ==
Criticism
Some programmers feel that these syntax usability features are either unimportant or outright frivolous. Notably, special syntactic forms make a language less uniform and its specification more complex, and may cause problems as programs become large and complex. This view is particularly widespread in the Lisp community, as Lisp has very simple and regular syntax, and the surface syntax can easily be modified. For example, Alan Perlis once quipped in "Epigrams on Programming", in a reference to bracket-delimited languages, that "Syntactic sugar causes cancer of the semi-colons". == Derivative terms ==
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 that programmers must jump through just to prove that they know what is going on, rather than to express a program action. In C#, when hiding an inherited class member, a compiler warning is issued unless the new keyword is used to specify that the hiding is intentional. To avoid potential bugs owing to the similarity of the switch statement syntax with that of C or C++, C# requires a break for each non-empty case label of a switch (unless goto, return, or throw is used) even though it does not allow implicit fall-through. (Using goto and specifying the subsequent label produces a C/C++-like fall-through.) Syntactic salt may defeat its purpose by making the code unreadable and thus worsen its quality – in extreme cases, the essential part of the code may be shorter than the overhead introduced to satisfy language requirements. An alternative to syntactic salt is generating compiler warnings when there is high probability that the code is a result of a mistake – a practice common in modern C/C++ compilers. Syntactic saccharin Other extensions are syntactic saccharin and syntactic syrup, meaning gratuitous syntax that does not make programming any easier. Sugared types Data types with core syntactic support are said to be "sugared types". Common examples include quote-delimited strings, curly braces for object and record types, and square brackets for arrays. == Notes ==
tickerdossier.comtickerdossier.substack.com