

On syntactic sugar
source link: https://evertpot.com/syntactic-sugar/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

August 13, 2022
On syntactic sugar
Ever so often the term ‘syntactic sugar’ comes when people discuss language features, and it’s not uncommon to see the word ‘just’ right in front of it; some examples:
The ‘just’ has a lot of meaning here. To me it suggests that language features that are ‘just’ syntactic sugar, aren’t quite as important as features that aren’t. Maybe it even suggests to me that the language would be fine without.
So while the above two examples both argue that both Javascript classes and async/await aren’t syntactic sugar, they also kind of come to the defence of those features and justify their existence. In other cases when people call something syntactic sugar, it’s often in a context that’s somewhat dismissal of the feature.
I think this is a bit odd and also confuses people, especially since any actual definition I’ve found is generally positive, such as this one from Wikipedia.
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.
The thing is, isn’t every language feature beyond the bare minimum of what makes a language turing-complete syntax sugar?
- You don’t need classes because you can use functions and structs.
- You don’t really need types because everything can fit in a string.
- Functions can be implemented with goto.
- Multiply can be implemented with addition.
or
andand
,xor
can be implemented withnand
.- async/await can be implemented with generators.
These are all incredibly useful features that make it easier to read and write code and express ideas. Almost every language feature could be considered syntactic sugar. That’s not a bad thing, it’s just uninteresting to point out.
Recommend
-
44
README.md Then
-
9
Syntactic Sugar Is Not Always Good This write-up is partly inspired by a recent post by Vlad Mihalcea...
-
11
Ruby Magic Syntactic sugar methods in Ruby Tom de Bruijn on Feb 20, 2018 “I absolutely love AppSignal.” Discover AppSignal
-
7
Syntactic sugar in C - (ab)using "for" loopsThe for loop is one of the most powerful constructions in the C language.It consists of three different parts. The first one is initialization, performed exactly once at...
-
9
What is syntactic sugar? In programming, the term syntactic sugar is used to describe some syntax that is meant to make some part of a programming language easier to read and express. Syntactic sugar means that the syntax does not...
-
7
-
7
Why async/await is more than just syntactic sugar#javascriptPublished on 08 August, 2022My takes on async/await vs PromiseDespite thousands of posts on async/await vs....
-
4
Syntactic sugar methods in Ruby
-
4
Oct 10th, 2022Syntactic Sugar, Declarative and First Class Citizens? What does that even mean?👇 Download Show
-
5
How to make use of the C# IO container less ugly. This article is part of an article series about the IO container in C#. In
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK