liveBook · Manning

Syntactic sugar

Syntactic sugar is language notation that makes an existing operation or construct more concise or convenient to express without changing its computational meaning.

How 2 Manning books explain it

The Well-Grounded Rubyist, Fourth Edition

Syntactic sugar is a language feature that provides a more convenient or readable syntax for expressing an operation supported by the language's ordinary rules.

How it is used
Makes Ruby method calls read like assignment, arithmetic, indexing, or other familiar operations.
How deep it goes
Explains the method calls behind setter and operator notation, including custom definitions, shortcuts, semantic pitfalls, and non-overridable operators.
Examples
Uses a ticket price setter, normalized travel year, custom `+`, bank-account `-=`, and arithmetic written as explicit method calls.
What you can do after
Build it from scratch by defining setter or operator methods, and diagnose/debug surprising operator behavior by checking those methods.

Read how The Well-Grounded Rubyist, Fourth Edition explains syntactic sugar →

Secrets of the JavaScript Ninja, Second Edition

Language syntax that makes an operation easier to read or write without adding new underlying capabilities.

How it is used
Makes class-like object setup, function expressions, and iterator traversal shorter or clearer to write.
How deep it goes
Defines the idea through three comparisons, including class-to-prototype mechanics and iterator next/done handling.
Examples
Uses a Ninja class, a sorting callback, and a generator loop to compare concise syntax with its mechanics.
What you can do after
Understand how class, arrow-function, and for-of forms relate to prototypes, function expressions, and iterator operations.

Read how Secrets of the JavaScript Ninja, Second Edition explains syntactic sugar →

Also covered in

What to know first

Related concepts

Questions about syntactic sugar

What is syntactic sugar?

Syntactic sugar is language notation that makes an existing operation or construct more concise or convenient to express without changing its computational meaning.

Which Manning books explain syntactic sugar?

The Well-Grounded Rubyist, Fourth Edition and Secrets of the JavaScript Ninja, Second Edition.

What should I know before learning syntactic sugar?

Manning books that teach syntactic sugar usually introduce attribute, function argument and function expression first.

What kinds of syntactic sugar are there?

Kinds of syntactic sugar include CSS nesting, do notation and function overloading.

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.