What is syntactic sugar?
source link: https://www.programmerinterview.com/technical-vocabulary/what-is-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.
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 actually add any extra functionality to the programming language – it’s really just an alternative syntax that’s easier for humans to read and use. The reason it’s called “sugar” is to make the experience of reading and using the programming language “sweeter” and easier for people.
An example of syntactic sugar
Suppose we have a structure in C that we will call someStruct. And, let’s say that someStruct has a member variable that we can call memberVariable. Now, we can access that member variable using this syntax:
(*someStruct).memberVariable
But, if we want to use some syntactic sugar instead, then we can just write it like this instead:
someStruct->memberVariable
Clearly, the second option is much easier to understand than the first. And that is our example of syntactic sugar in C.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK