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.
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.
xorcan be implemented with
- 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.