Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I love it!

As someone else also mentioned in the comments, it is unapologetically dynamic. In many ways, this reminds me of Perl. The array destructuring assignment is such a common pattern in that language (eg. http://perldoc.perl.org/functions/caller.html)

What's even more exciting/terrifying is that ES6 goes even beyond the patterns allowed in Perl!



No, it's worse. I'm talking about the part where you want to pull only parts off a compound:

ES6:

    let [,,,,,,,,, tenth_item] = somearray;
Perl:

    my (undef x 9, $tenth_item) = @somearray;
The ES language designers got that wrong. You carefully have to count the number of commas, and use an invisible nothing in between. Instead they should have made it so that you assign to undefined, or perhaps null, or make up a new special identifier named _ (like it is used in some other languages) and then the assignment operation is smart enough to discard the value.

This is not only better because now there is a visible thing to see and talk about, but also allows the comma operator to be much less restricted and frees the programmer to be more expressive. In Perl, multiple commas are collapsed similar like multiple whitespace collapses in HTML. The expression a,,,,,,b is identical to a,b – also it does not matter where in the expression the multiple commas are.

In ES5 and later multiple commas at the end are collapsed into one, but otherwise multiple commas are kept. This is lame because inconsistent.


What do you think of the destructuring features in Perl 6 as discussed for example at http://perlgeek.de/blog-en/perl-6/2013-pattern-matching.html?


You could just write:

         let [tenth_item] = somearray.slice(9)


You're missing the point here. Slice works with only part of the compound about to be ripped apart. However, destructuring with commas is generic. Example that has no simple slice method call:

    let [,second,,fourth,,sixth]




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: