A Spoonful of Syntactic Sugar

To be technical, besides assembly languages, programming is all syntactic sugar. It’s all a linguilogical analogy for what’s going on under the hood. I just made up a word to quickly relay my point. Instead of linguilogical, I could have said “a language-based and logically driven analogy.” If I were feeling really obnoxious, I could have said “an analogous, semantically delivered framework underpinned with a foundation of computational logic, giving movement-orders to a binary mechanism”.

But who has time for that?

ES6 is literally all about syntactic sugar, but it’s the accumulation of small delightful changes that transforms the latest Javascript experience into an altogether more powerful medium.

Arrow functions, besides trimming the fat, look way cooler.

function(s){ return s.length });

s => s.length;

Template literals make me unreasonably happy. I can dynamically ascribe meaning to my strings without an obnoxious plus-symbol slowing me down.

//Which one do you prefer?
var creature = {

species: 'ogre',
id: 8743,
meal: 'whole lamb'
creature.alert("Greetings" + this.species + " number " + this.id + "," + "how many " + this.meal + "s would you like today?");
creature.alert(`Greetings ${this.species} number ${this.id}, how many ${this.meal}s would you like today?`);

Comparing the two ways of interpolating shown above, one requires almost no interpretation. A non-programmer could pick up the template literal and immediately understand what it’s relaying. A non-programmer might look at the first and wonder: “Why am I doing math with words? What is an ‘s would you like today?’ I wonder what that “,” command does…”

These treatments make Javascript look almost like python. Don’t tell any python programmers I said that. I can even pretend I have literally declared classes.

Class Javascript extends Computer {
  constructor(options) {

this.options = {
syntacticSugar: true
    isThisBetterThanES5 = notNecessarilyButItSureIsPretty; 

No commas to delineate my methods?! No literal function declarations?!?! Are you telling me my browser’s Javascript interpreter can just…deduce from the parenthetic structure that those are methods without my telling it?

The great irony is that syntactic sugar takes more work (behind the scenes). Okay, it’s a very super tiny bit more work, but it’s worth thinking about. I’m making my code look more concise and cleaner, but it’s taking the tiniest (tiniest!) bit longer to tell the interpreter one more underlying instruction.

Maybe more interesting is that while it’s making my code look almost more primitive, closer to assembly, as if it’s speaking more directly to my computer, I’m doing the opposite. I’m increasing my metaphorical distance from the machine source at the benefit of making it much clearer, more intuitive, and just plain more fun.

Just, you know…don’t forget your roots. It all started with Ada Lovelace’s punchcards, mutated into a strip of Turing tape, evolved into bits, all leading to much more conveniently delivered ogre greetings.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.