News for hackers. Stuff that matters.
Re:Node.js ES2015/ES6 support by neals on Monday April 25, 2016 @07:39AM (#11563583)
So I'm an above average JS developer. I feel save saying this and claiming this.

I would never use most of the exotic new stuff and I would probably never use any of the red stuff.

I'm not saying it shouldn't be in there. I love that JS can be a fit for everybody. I just wonder how much we're gonna be adding and when it's enough...

Re:Node.js ES2015/ES6 support by ry_ry on Monday April 25, 2016 @09:50AM (#11564148)
Out of curiosity, what is your definition of an average js dev?

Are we talking 'does not use many jQuery plugins these days' or 'regular contributor to ${framework}' here?

Re:Node.js ES2015/ES6 support by terda12 on Monday April 25, 2016 @10:20AM (#11564333)
Some things I like about ES6

1. Arrow functions are really handy:

  ["the", "red", "fox"].map(word => console.log(word))
is much cleaner than

  ["the", "red", "fox"].map(function(word) {
      console.log(word)
  })
2. Imports, while more ambiguous than `require`, look quite nice:

  import React, { Component } from 'react';
  import Block from './Block';
vs

  var React = require('react');
  var Block = require('./Block');
3. Exports are cleaner and streamlined

  export default myFunction()
vs

  module.exports = myFunction()
So while ES6 is more ambiguous than ES5 and has a higher learning curve, I think it's much cleaner and looks more like a proper programming language. ES5 feels like a homegrown hacky language in comparison.
Re:Node.js ES2015/ES6 support by mbrock on Monday April 25, 2016 @11:08AM (#11564670)
The code I write in ES2015 makes very heavy use of arrow functions, destructuring parameters, the ellipsis syntax for extending arrays and objects, and the syntax for evaluated object literal keys.

Random example:

    DRAFT_LOADED: ({
      state: { drafts },
      payload: { draft }
    }) => ({
      drafts: {
        ...drafts,
        [draft.id]: draft
      }
    })
In classic JavaScript, I'd have to write something like:

    RESULTS_LOADED: function(state, payload) {
      return {
        drafts: Object.assign(
          {}, state.drafts,
          keyValue(payload.draft.id, payload.draft)
        )
      }
    }
The new syntax rules combine to significantly improve the clarity of this kind of transformation function.
Re:Node.js ES2015/ES6 support by z3t4 on Monday April 25, 2016 @03:37PM (#11566740)
hmm. Looks like some sort of exploit. Tried to run it in node and got some weird error I haven't seen before. Did you just pwn me?
Re:Node.js ES2015/ES6 support by mbrock on Monday April 25, 2016 @04:34PM (#11567115)
haha, no... I haven't tried it in pure Node, I'm using Babel for transpiling.
Re:Node.js ES2015/ES6 support by minitech on Monday April 25, 2016 @02:01PM (#11566029)
I don’t find the arrow function version of (1) cleaner than the anonymous function version. Is it cleaner because you can fit it on one line?

I don’t find the import version of (2) cleaner than the require() version. Having a boring old function that’s consistent with the rest of the language actually seems better than dedicated syntax, especially when that dedicated syntax is unnecessarily verbose. Copying Python’s might have been okay:

  // I have to repeat “fs” =(
  var fs = require('fs');

  // Wait, I still have to repeat “fs” *and* it’s longer
  // *and* it looks more confusing? There’s no precedent
  // for this use of * in JavaScript.
  import * as fs from 'fs';

  // Nice.
  import fs;
I don’t find the `export default` version of (3) cleaner or more streamlined than the one that assigns to `module.exports`. It just seems like another waste of dedicated syntax.
Re:Node.js ES2015/ES6 support by tracker1 on Monday April 25, 2016 @03:10PM (#11566521)
how about...

    return myArray.map(item => `I am ${item}, yo!`);
vs

    return myArray.map(function(item){
      return 'I am ' + item + ', yo!';
    });
There are a lot of one liners that are much more composable in the fat-arrow syntax. The default returns takes a lot of it out, and makes it simpler the simpler it starts.

Beyond this, the above also uses templates, which you can even create custom processors for templates...

    var result = await sql`
        SELECT *
        FROM
          a
        WHERE
          a.foo = ${bar}
    `
You can create an sql processor that turns that query as a template into a parameterized query for the database, that returns a promise, which inside an async function can be awaited directly... I wrote a few libraries that did just that to make using sql, bigtable (azure tables), queues and other pieces really easy to use... With that I was able to write data migration scripts with ease... it was really awesome to see.

Your second example is only if there's no default export... the local name doesn't have to match the name of the module, also modules can be `foo.bar` or `foo_bar` or `foo-bar` which can't be a single value within the script... so it creates a disconnect there, requiring the localized in-script name.

Re:Node.js ES2015/ES6 support by minitech on Monday April 25, 2016 @06:05PM (#11567759)
> There are a lot of one liners that are much more composable in the fat-arrow syntax. The default returns takes a lot of it out, and makes it simpler the simpler it starts.

They’re not more composable… they’re slightly shorter, and anything non-trivial doesn’t fit on one line. Template literals are nice, sure.

> the local name doesn't have to match the name of the module,

But when it does, everything is a lot more obvious. It works fine for all the Python modules, too.

Re:Node.js ES2015/ES6 support by tracker1 on Tuesday April 26, 2016 @05:12PM (#11575666)
Try the following without fat-arrow syntax off of an object

    {
      foo: (a,b) => doFoo(this, a, b, 'fixed-value')
    }
I find the fat-arrow syntax allows for much more dynamic flows that are easy to understand, more so than bind, and like the above, where bind wouldn't work.

There's a lot of oneliner possibilities when you get rid of 12+ characters `function(){ return ` ... Also, I find the fat-arrow syntax looks better in a lot of cases, where you might use bind.

Re:Node.js ES2015/ES6 support by BinaryIdiot on Monday April 25, 2016 @08:40AM (#11563800)
While I hold your same opinion I think you're being down voted for not elaborating on the way as it appears you're only ranting and not adding anything to the conversation.

For me most of my work in node needs to work over multiple versions and most of my browser work also needs to work over multiple browsers. Transpiling with Babel means I can't debug the code I actually wrote (even mappings won't work in all browsers or older ones) and I don't need extra, unnecessary complexity added to my build and development.

I like many of ES6's features but I value simplicity over almost everything so I can only hope to use it at some point in the future.

Re:Node.js ES2015/ES6 support by Keepo on Monday April 25, 2016 @08:05AM (#11563682)
Can you elaborate more on what features you would never use and why please?

> I feel save saying this and claiming this

Is `this` some kind of pun? When I was learning JS I never felt safe around this:)

Re:Node.js ES2015/ES6 support by seanclayton on Monday April 25, 2016 @08:51AM (#11563851)
Keep on using the old stuff then — crisis averted.
Re:Node.js ES2015/ES6 support by spriggan3 on Monday April 25, 2016 @09:25AM (#11563986)
It doesn't matter if you don't use them, libraries that you might depend on will use them, and you have to know the new syntax in order to read javascript code from now on.
Re:Node.js ES2015/ES6 support by drinchev on Monday April 25, 2016 @10:37AM (#11564433)
I will be pretty happy if I see non-ES6 code if it is properly structured and documented well.

Nevertheless if I see people has just replaced `class` with `jQuery.extend` or with some other helper tool it would be a downside. Also we are talking about lodash vs native implementation.

That's one of the reasons I stopped working with coffeescript.

Re:Node.js ES2015/ES6 support by nkohari on Monday April 25, 2016 @08:03AM (#11563679)
Languages constantly evolve. Java was created 20 years ago and it's still receiving regular updates.
Re:Node.js ES2015/ES6 support by mkohlmyr on Monday April 25, 2016 @08:30AM (#11563768)
Obviously this is true, but I kind of agree with him.

So far I don't use the overwhelming majority of new features and it does sort of seem like JavaScript is in some kind of race with itself to implement every paradigm and idea that anyone latches on to.

There is beauty in simplicity and commonality in code. I don't think there would be anything wrong with taking a more conservative approach to adding new language constructs.

JavaScript needed a class syntax. It needed block-scoped variables. It needed better parameter syntax and object loops. Generators are great. I'm not sure how much else of what is being added is strictly necessary as opposed to a technological debt for the future that must be supported for compatibility.

Re:Node.js ES2015/ES6 support by tracker1 on Monday April 25, 2016 @03:20PM (#11566611)
Did it really need class syntax? I mean, there are a lot of us following functional patterns as much as possible, and I feel that I rarely need class syntax... I mean it's kind of nice for a react component, but even then, not something that couldn't easily be represented with static objects.

I rarely use classes, or for that matter constructor functions... a lot of the code is far easier to follow and reason that way.

As to block-scoped variables, understanding that variables were scoped to the function they are declared in wasn't a huge hinderance, and is part of the reason why the new stuff runs slower... creating that scope has overhead.

I'll add that destructured assignment and string templates are huge... taking generators the next step to async functions with await is very nice as well, not that co didn't work.

Fat-arrow syntax cuts quite a bit of typing out with a default return.

Each piece is valuable to some, and collectively not everything is valuable to some... Just because you don't see the value, doesn't mean that nobody does.

I, for example, will probably not use the WeakMap/Map/Symbol in practice... But I see how someone can find those valuable additions.

Re:Node.js ES2015/ES6 support by ufmace on Monday April 25, 2016 @11:01AM (#11564620)
As far as using the new features, how many people actually can/are? I can agree that they're needed, and I'm glad that they're coming, but support in browsers is variable at best, meaning you can't really use it in the front-end for anything in production without a transpiler, which IMHO mostly defeats the purpose. When you try to actually debug something, you have to deal with the mental translation of going back and forth between the translated/compiled stuff that's actually running and the source code.

Could be different for stuff running in Node on the server, but then according to this, Node native support for ES6 features varies between bare-bones and not very tested to nonexistent. So we're back to transpilers again, not quite as much of a pain on the server, but still not great.

Re:Node.js ES2015/ES6 support by likeclockwork on Monday April 25, 2016 @09:31AM (#11564025)
> JavaScript needed a class syntax.

Did it? Or is that just a paradigm you've latched on to?

Re:Node.js ES2015/ES6 support by mkohlmyr on Monday April 25, 2016 @09:46AM (#11564120)
You got me..

Although the multitude of awful shims people invented would tend to support my assessment that a singular way of doing things was needed. Oh, and all the blog posts explaining "this" and prototype inheritance..

I take it back, you didn't get me. JavaScript needed a coherent common syntax for doing what everyone was trying to do anyway.

Re:Node.js ES2015/ES6 support by shriek on Monday April 25, 2016 @08:16AM (#11563719)
While I agree with you I also don't believe in adding things just for the sake of adding features. Remember, once you put a feature in a language it's going to remain in it forever and slowly the language can get bloated with lot of history in it's baggage (not that js already doesn't have this).