What do you mean by term “Syntactic Sugar”?

For many of us term Syntactic Sugar could be something out of this world and the term is too much heavy that anyone would wonder about this alien word. But many times the concept behind such terms is very simple. Now let’s make this word easily understandable. In such cases, I always split the term into separate words and try to understand the meanings of individual words in programming world prior to understand actual meaning the term.

So below is the diagram how I understand this term,

Syntactic Sugar
Syntactic Sugar

What is referred by the full term “Syntactic Sugar”?

  • Syntactic Sugar is used in many programming languages and are more expressive in Functional Programming
  • Syntactic Sugar is a simplified syntax structure
  • Syntactic Sugar is a compact syntax structure
  • Syntactic Sugar is very easy to understand
  • Syntactic Sugar is an intuitive and expressive way of defining basic programming constructs

So finally I think now we are in a better condition to structure a proper definition,

Syntactic Sugar can be referred as a feature in Programming world which provides more compact and simplified structure which explains the basic idea or logic.

In earlier versions of Java we have used many syntactic sugar examples.

int x, y = 1;
int z = 0;

//Normal examples
//1. Increment By 1
x = x + 1;

//2 Add two values
y = x + y;

//3 Conditional Assignments
if(y == 3){
    z = y;
} else {
    z = x;

//Examples with syntactic sugar
//1. Increment By 1

//2 Add two values
y += x;

//3 Conditional Assignments

Presently you might be thinking, “What is the point to discuss this term?”

So the answer is, Java 8 has introduced new feature called lambda expressions which brings numerous new syntactic sugar examples (we’ll more explore them in my other posts). And not only Java but there are many functional languages (like Scala) also have similar structures and this term is widely used in the universe of Functional Programming.

One thought on “What do you mean by term “Syntactic Sugar”?”

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>