Live data from Hacker News

What’s New in ES2019

blog.tildeloop.com

361–370 of 411 posts

Re: What’s New in ES2019

#361
post #78

That array.flat() and array.flatMap() stuff is great to see. Always having to rely on lodash and friends to do that type of work. Exciting to see how JS is evolving.

I wonder if there are enough use-cases for .flat to not default to Infinity. It's also confusing that `arr.flatMap()` is not equivalent to `arr.map().flat()`, but to `arr.map.flat(Infinity)`

Infinity was originally the default (which feels intuitive), but here's the argument for changing it [0]:

"I think Array#flatten should be shallow by default because it makes sense to do less work by default, it aligns with existing APIs like the DOM Node#cloneNode which is shallow by default, and it would align with the existing ES3 pattern of using Array#concat for a shallow flatten. Shallow by default would also align with flatMap too."

[0] https://github.com/tc39/proposal-flatMap/issues/9

Re: What’s New in ES2019

#362

Earlier quoted context omitted.

> If we still need to target es5 4 years later, and transpilation is standard practice, why bother? Is the evolution of JS not directed in practice by the authors of Babel and Typescript? If no one can confidently ship this stuff for years after, what’s the incentive to even bother thinking about what is official vs a Babel supported proposal. For one, not everyone works on the client. I can write for Node and use ev…

> I can write for Node and use everything v8 supports without ever touching Babel and Typescript. You totally can do that--but you probably shouldn't, because writing TypeScript is better for you and for future you. ;)

How will TypeScript instead of plain JS help the future me? Unless of-course you meant that as a joke (going by the wink).

Re: What’s New in ES2019

#363

arr.flat(Infinity) seems like a strange decision for flattening the entire array - wouldn't the most common number of levels to flatten an array be all levels, in which case I'd expect arr.flat() to flatten the whole array but in this case it's just 1 level.

Infinity was originally the default (which feels intuitive), but here's the argument for changing it [0]:

"I think Array#flatten should be shallow by default because it makes sense to do less work by default, it aligns with existing APIs like the DOM Node#cloneNode which is shallow by default, and it would align with the existing ES3 pattern of using Array#concat for a shallow flatten. Shallow by default would also align with flatMap too."

[0] https://github.com/tc39/proposal-flatMap/issues/9

Re: What’s New in ES2019

#364

arr.flat(Infinity) seems like a strange decision for flattening the entire array - wouldn't the most common number of levels to flatten an array be all levels, in which case I'd expect arr.flat() to flatten the whole array but in this case it's just 1 level.

Infinity was originally the default (which feels intuitive), but here's the argument for changing it [0]: "I think Array#flatten should be shallow by default because it makes sense to do less work by default, it aligns with existing APIs like the DOM Node#cloneNode which is shallow by default, and it would align with the existing ES3 pattern of using Array#concat for a shallow flatten. Shallow by default would also a…

I’m trying to think of a single use case where I’d want to flatten exactly one level of an array and can’t.

Re: What’s New in ES2019

#365
post #167

Earlier quoted context omitted.

> That's not unique to JS. Some compilers took over a decade to implement C99 features. I sometimes wonder what's the point of new versions of C, too. Also, a new feature I want to use needs only be supported by one C compiler: the one I'm using. With JS, I need all of them to support it.

I don't think I ever write C code that I intent to only be compiled using one compiler. One of the primary reasons I use C is to write cross-platform code, so I care about GCC, Clang, and VS, at least.

GCC and Clang are both cross-platform, and users typically don’t care about which compiler you used to produce the binary. At least until the early 2010s plenty of projects used GCC-specific features and wouldn’t compile with Clang. The situation must be better now but I bet GCC is still the only blessed compiler for many maintenance-only code bases.

Re: What’s New in ES2019

#366

Earlier quoted context omitted.

Nice. I like use of the let/var/const keyword to disambiguate from the accidental `if (x = y)` when intending to use `==`.

Only helps with const. Better use linting to avoid such issues.

> Only helps with const.

Can you elaborate?

Re: What’s New in ES2019

#367
post #3

It's great to see JS getting some of the features of better planned languages. But I'm still very nervous about some of the stuff mentioned here with regard to mutation. Taking Rust and Clojure as references, you always know for sure whether or not a call to e.g. `flat` will result in a mutation. In JS, because of past experience, I'd never be completely confident that I wasn't mutating something by mistake. I don't…

You could always look at ClojureScript. I know I am.

  Array.flat() => flatten
  Array.flatMap() => mapcat
  String.trimLeft() => triml, trimr 

Symbols are great but they’re much more useful when you can write them as (optionally namespaced) literals, which are much faster to work with:

  (= :my-key :your-key) ;; false
  (= :my-key :my-key) ;; true

Object.entries() and Object.fromEntries() are both covered by (into). You can use (map) and other collection-oriented functions directly with a hashmap, it will be converted to a vector of [k v] pairs for you. (into {} your-vector) will turn it back into a new hashmap.

And...all of these things were already in clojurescript when it was launched back in 2013! Plus efficient immutability by default, it’ll run on IE6, and the syntax is now way more uniform than JS. I’m itching to use it professionally.

Re: What’s New in ES2019

#368
post #162

Earlier quoted context omitted.

In JS, the pattern is the type. That is the point of duck typing.

> In JS, the pattern is the type. How do you match against a `Buffer` pattern/type?

In the current proposal,

    case (value) {
        when { constructor: Buffer } ->
            console.log("It's a Buffer!")
    }
that doesn't handle subtying though and doesn't work across realms.

Re: What’s New in ES2019

#369

Earlier quoted context omitted.

> In JS, the pattern is the type. How do you match against a `Buffer` pattern/type?

In the current proposal, case (value) { when { constructor: Buffer } -> console.log("It's a Buffer!") } that doesn't handle subtying though and doesn't work across realms.

Oh interesting you can match on that!

However I think my point stands that javascript has runtime conceptions of types that go beyond duck typing.

Re: What’s New in ES2019

#370

Honest question, not meant to be inflammatory. If we still need to target es5 4 years later, and transpilation is standard practice, why bother? Is the evolution of JS not directed in practice by the authors of Babel and Typescript? If no one can confidently ship this stuff for years after, what’s the incentive to even bother thinking about what is official vs a Babel supported proposal. I like the idea of idiomatic…

A few off the top of my head: 1. Node.js greatly benefits from these features. Transpiling is not as prevalent there 2. Some people do exclusively target "evergreen" browsers and don't care about IE support 3. Those that do differential bundling (different bundles per browsers) can see quite a performance boost by not transpiling on newer browsers

Ad 2) It isn't just about IE anymore as more and more older machines become outphased for current OSes. E.g., for a 10 years old Mac Pro, which is still a viable machine, Firefox is currently the only evergreen option which is still receiving updates. (Safari is largely OS-dependent, as is WebKit, and Chrome/Chromium cancels support as soon as the OS is phased out.)
Post reply on HN