News for hackers. Stuff that matters.
Re:Future JavaScript: what is still missing? by danShumway on Sunday January 27, 2019 @11:23AM (#19012275)
I feel like there's something I'm missing with do expressions. Are they purely syntactic sugar? What can I do with a do expression that I can't do with an immediately invoked anonymous function?

The examples the article gives don't really look all that syntactically different to me.

  const func = (() => {
    let result; // cache
    return () => {
      if (result === undefined) {
        result = someComputation();
      }
      return result;
    }
  })();

  const func = do {
    let result;
    () => {
      if (result === undefined) {
        result = someComputation();
      }
      return result;
    };
  };
And I guess I wouldn't be able to recurse in a do expression like I can with a named function? So it's not like I can actually universally stop using immediately invoked expressions everywhere.
Re:Future JavaScript: what is still missing? by tristanstcyr on Sunday January 27, 2019 @12:44PM (#19012761)
Syntactic sugar I not a bad thing. In any sufficiently complex language, most features can be simulated with other primitives. If we didn't want that, we'd all be writing lisp.

In this specific case, the IIF is harder to read. You have to go all the way to the end of the expression in order to realize intent. With 'do', you see it right away.

Like anything in engineering, it's a question of trade-offs. Do the benefits of better readability outweigh the downside of making the language more complex?

Re:Future JavaScript: what is still missing? by snek on Sunday January 27, 2019 @11:54AM (#19012481)
They also inherit break/continue/yield/await/return/etc, which an iife will cut off.
Re:Future JavaScript: what is still missing? by burlesona on Sunday January 27, 2019 @11:27AM (#19012297)
You’re not missing anything, as shown in the article it’s just sugar.