Destructuring in ES6 is a somewhat more developed form of the unpacking assignment syntax that python and some other languages have had for a while. In a nutshell, it lets you easily assign to multiple variables in a single statement, by automatically pulling values out of an array or object (or both).
In the world of programming language design, this type of feature is referred to as syntactic sugar. Sugar is something that saves you keystrokes or generally makes it easier to write the code, without actually providing any functionality that wasn’t previously there.
I have mixed feelings about syntactic sugar. The stodgy old dog programmer in me thinks sugar is wasteful. It complicates the language, obscures concepts and commonalities, and is only of value to people who are lazy and/or can’t type fast.
However, the side of me who has spent the last six or seven years writing extensively in python (arguably one of the more cloying languages out there) doesn’t want to have to write a separate statement to assign each element of a sequence to a different variable, and doesn’t want to have to write for loops to populate a sequence when I could just use a comprehension.
I think I finally came around to accepting sugar when I took a few days to explore perl a little bit. Now I never got too far into perl, but my overall impression was the perl is awful. Like, PHP awful. However, for those who haven’t played with perl before, perl has two interesting keywords, “until” and “unless”. Both of these are syntactic sugar in its rawest form. “Until” is simply “while not …”, and “unless” is simply “if not …”. Sounds kind of silly, right? In the latter case, it doesn’t even save you any keystrokes!
But seeing these two keywords, I realized the true purpose of sugar. It isn’t for the person writing the code. It’s for the person reading the code (which, of course, may very well be the same person, only a few months later). A statement like “if not hasNoChildren” is slightly confusing to a human. The double negative creates a little knot in your thought process and delays you by a half beat. Written as “unless hasNoChildren” is ever so slightly more clear and direct. Logically and linguistically, it’s still a double negative, but “unless” is a concept in itself, as opposed to “if not”, which is really two concepts that your brain has to deal with.
I think the time for sugar has come, as has the time for the Mels of the world to let go of their macho ideas about what constitutes a real programmer. With the exception of the IOCCC, programming is not about writing the most clever, most compact, most obscure code you can. It’s about creating the best product you can, and in the modern world, that means writing code that others can read, understand, review, evaluate, test, and expand.