News for hackers. Stuff that matters.
Re:Overview of JavaScript ES6 features by zelias on Monday October 24, 2016 @11:45AM (#12779835)
While I'm a big believer in most of the ES6 changes (arrow functions! let/const! classes! generators!), I am not a big fan of many of the new destructuring features. They can actually make your code less approachable if you don't already know what's going on.
Re:Overview of JavaScript ES6 features by i__believe on Monday October 24, 2016 @02:15PM (#12781295)
Exactly, and this is a big problem where I work. I believe code should be readable, even by those with only cursory knowledge of the language. Object shortcuts is also a problem I think. For example, I had a method like this:

const getObj = (id, store) => { return { id: id name: store.something.name }; };

The linter gave an error on it because I used {id: id}. It was like the linter was trying to make my code harder to read.

I think es6 in the wrong hands quickly falls prey to the problems of ruby/scala where it can become incredibly terse and hard to parse unless you are used to the author's particular style.

Re:Overview of JavaScript ES6 features by gidan on Monday October 24, 2016 @04:51PM (#12782774)
You know instead of:

  const getObj = (id, store) => { return { id } }
You could write:

  const getObj = (id, store) =>  ({ id })
Re:Overview of JavaScript ES6 features by i__believe on Monday October 24, 2016 @07:35PM (#12783873)
I'm pretty sure that's a good illustration of my point.
Re:Overview of JavaScript ES6 features by dwaltrip on Tuesday October 25, 2016 @12:49AM (#12785372)
This is a matter of personal preference.

I find `return` to be quite distracting and annoying for a small function that spans part of a line, while you and some others may prefer the explicitness of the `return` keyword.

I would agree that nested destructuring should be used quite cautiously. Code legibility is incredibly important to the success of any serious project.

Re:Overview of JavaScript ES6 features by Roboprog on Monday October 24, 2016 @12:22PM (#12780226)
The deep matching gets too cluttered, but the simple case I find to be quite readable and useful:

http://es6-features.org/#ObjectMatchingShorthandNotation

Re:Overview of JavaScript ES6 features by BinaryIdiot on Monday October 24, 2016 @01:26PM (#12780853)
I completely agree and it's nice to see someone else with the same thoughts because I've found a ton of opposition regarding this. I hate the destructuring syntax. While I understand how it works now I felt like it took me too long and feels very non-obvious so I try to avoid it in my code unless absolutely impossible to avoid. I don't find it intuitive especially for newer developers.
Re:Overview of JavaScript ES6 features by fryan on Monday October 24, 2016 @12:06PM (#12780049)
I agree that object destructuring makes the code far less readable. Array destructuring however is easy for anyone to grok.
Re:Overview of JavaScript ES6 features by ggregoire on Monday October 24, 2016 @12:18PM (#12780177)
It depends I think.

For example, in my opinion

    const Header = ({ children, iconName, iconSize, title }) => { ... };
is more readable than

    const Header = (props) => { ... };
Re:Overview of JavaScript ES6 features by fryan on Monday October 24, 2016 @01:44PM (#12781026)

    const Header = ({ children, iconName, iconSize, title }) => { ... };
Once you get used to the destructuring parameter idiom, sure. It also conveys more information.

But that statement is overloaded in that it makes use of implicit object shortcuts which has a bit of a learning curve for longtime ES5 users.

    const Header = ({
        children: children, 
        iconName: iconName, 
        iconSize: iconSize, 
        title: title }) => { ... };
When object destructuring is nested it can be confusing and more verbose.
Re:Overview of JavaScript ES6 features by lhnz on Monday October 24, 2016 @05:28PM (#12783086)

  function thisIsBad ({
    someKey: renamedSomeKey,
    someOtherKey: renamedSomeOtherKey = 'otherDefaultValue',
    meta: { innerMetaKey = 'someInnerMetaKeyValue', otherInnerMetaKey, ...remainingMeta }
  } = {
    someKey: 'defaultValue',
    someOtherKey: SOME_CONSTANT,
    meta: {}
  }) {
    // ...
    return { someKey: renamedSomeKey }
  }
My favourite messed up part of the syntax is the way the `:` character is used to describe either the default value of a property or a way of renaming the name of a property internally (depending on whether it is to the left or right of an `=`). And also, the way you can destructure the inside of an object, and automatically lose the original value. For example `meta` is not accessible within the function defined above.

This is syntax which can simplify your code if you apply it carefully, but will ruin your code if you over-use it.

Re:Overview of JavaScript ES6 features by fryan on Monday October 24, 2016 @05:54PM (#12783233)
I had to debug code like that the other day. Before you debug it you have to mentally grok wtf is going on. What a mess.
Re:Overview of JavaScript ES6 features by Semiapies on Monday October 24, 2016 @02:09PM (#12781241)
And suddenly I get it. Very nice example.
Re:Overview of JavaScript ES6 features by wildmusings on Monday October 24, 2016 @12:38PM (#12780397)
I agree about the object destructuring. The examples set off loud alarm bells in my head. Very cute and very unreadable.

Like others are saying, though, the array destructuring seems fine.