liveBook · Manning

Syntactic sugar

Syntactic sugar is language syntax that provides a more convenient or readable form for expressing behavior already representable by other constructs without changing its 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 →

Related concepts

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.