Live data from Hacker News

What’s New in ES2019

blog.tildeloop.com

371–380 of 411 posts

Re: What’s New in ES2019

#371
post #11

Earlier quoted context omitted.

Yes, this is a real problem and I've been bitten by it more times than I can count. Now I always keep this handy website ready: https://doesitmutate.xyz/

For what it's worth, there are only two, maybe three methods in that entire list that mutate where it's not obvious: sort, reverse, and (maybe) splice. All the other methods (like push, pop, fill, etc) are methods whose entire purpose is to mutate the array.

That was my first impression. But then the same logic applies to concat. ("I want to add another array").

Re: What’s New in ES2019

#372

Earlier quoted context omitted.

> 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).

Type safe code improves code readability, and the future you will most likely read the code you are writing today.

Re: What’s New in ES2019

#373
post #139

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…

That's not unique to JS. Some compilers took over a decade to implement C99 features. Most of us C coders were still defaulting to C89 for portability well into the late 00's. But now C99 is mainstream enough that you can (mostly) safely target it. If you never release new standards you'll never be able to use them. I realize that in JS world 4 years is basically an eternity so it's hard to project that far but I'm s…

As of VS2017, MSVC still missed a bunch of C99 features (or they're buggy as hell):

> Variable Length Arrays are not supported (although these are now officially optional)

> restrict qualifier is not supported, __restrict is supported instead, but it is not exactly the same

> Top-level qualifiers in array declarations in function parameters are not supported (e.g. void foo(int a[const])) as well as keyword static in the same context

They only started seriously working on actual C99 support (aside from the bits of C99 which were part of C++) for VS2013 or so.

Though to be fair it seems both Clang and GCC are still missing bits and bobs:

> The support for standard C in clang is feature-complete except for the C99 floating-point pragmas.

for GCC I found https://gcc.gnu.org/c99status.html, it's unclear how up-to-date it is, and if GCC is still missing any required feature.

Re: What’s New in ES2019

#374
post #207
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.

> Also, a new feature I want to use needs only be supported by one C compiler: the one I'm using. I've always had the impression that C programmers also care about standards compliance, and aren't typically willing to marry their project to a particular compiler. At least, it's the language community where you see "language lawyers". I'm sure there are "language lawyers" in other language communities, but I've never…

Maybe C++ programmers care about standards compliance. C programmers care about what gcc does.

Re: What’s New in ES2019

#375

Earlier quoted context omitted.

They could have also implemented flat in terms of flatMap: flatMap(x => x) I personally feel flatMap is a much more used method than flat, so if you want to remove one, I would remove flat.

> They could have also implemented flat in terms of flatMap: flatMap(x => x) Flat can flatten any level of nesting (it just defaults to 1), so would be difficult to implement in terms of flatMap.

You could reproduce that behaviour of 'flat' by doing something like:

    function flatten(x, n=1) {
        return n > 0 ? x.flatmap(y => flatten(y, n-1))
                     : x;
    }

Re: What’s New in ES2019

#376

Earlier quoted context omitted.

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)`

According to MDN `arr.flatMap()` is indeed equivalent to `arr.map().flat()` (without the Infinity). [1] Testing in the Chrome Devtools it also seems to be the case: x = [[[1, 2]], [[2, 3]], [[3, 4]]] x.flatMap(x=>x) output: [[1,2], [2,3], [3,4]] x.map(x=>x).flat() output: [[1,2], [2,3], [3,4]] x.map(x=>x).flat(Infinity) output: [1, 2, 2, 3, 3, 4] [1]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe... >…

Ah, I missed that. I though flatMap had depth of Infinity.

Re: What’s New in ES2019

#377

Earlier quoted context omitted.

>> However, it still can be quite confusing. I don't know - it's never confusing to me. I just use the IDE that allows me to view the types of the variables whenever I need to see them. IDE also highlights the definitions and then the usages of the variable, including the syntax scope where it's used. You're definitely using the wrong tools for the job if you get confused with that little detail. >> Given that JS doe…

var and let tell the compiler the scope in which it should declare the variable (oversimplifying). If var or let are not present, the variable is declared in the global scope; unless you're in strict-mode, then you get a scolding. So var and let are only tangential to the whole declaration process and only indicate the scope in which the variable is bound. I feel confused. Why do you want your assignment statements t…

if you put var in-front you don't have to worry about reassigning a variable from parent scope. You also make assignment and comparison semantically different, example var foo=1; vs foo=1 if(foo=1) and it's thus easier to spot bugs and understand the code.

Re: What’s New in ES2019

#378

Earlier quoted context omitted.

I always assumed it was to protect against: accidental naming errors, confusion of what a declaration is and copy/paste issues. When I first started writing rust and saw it was a thing I thought it was a terrible idea. I'm a more open towards it now, the strong static analysis Rust does help and it can improve code quality if used in small amounts. However, it still can be quite confusing. Given that JS doesn't restr…

>> However, it still can be quite confusing. I don't know - it's never confusing to me. I just use the IDE that allows me to view the types of the variables whenever I need to see them. IDE also highlights the definitions and then the usages of the variable, including the syntax scope where it's used. You're definitely using the wrong tools for the job if you get confused with that little detail. >> Given that JS doe…

What IDE (+plugins?) are you using ?

Re: What’s New in ES2019

#379

Earlier quoted context omitted.

The truth is that if you need to declare a variable outside your current scope you should probably declare it in the outside scope in the first place. In the scenario with var/let I need to grok the code in order to tell which variables are visible in my current scope.

I tend to mainly use const, let only when necessary. I never use var and set linter to scream about it at me. IE11 supports it, so unless you develop application for IE compatibility mode (my condolences) I don't see a reason to use var. On the other hand var mainly bites you when declaring closures inside loops, also hoisting is just plain weird.

I find hoisting a convenient feature as I can declare the variable in context to where it's used. It means I do not have to break the flow of how the code reads, making the code easier to understand and less bug prone. Example:

    if(something) var foo = 1;

Re: What’s New in ES2019

#380
post #81

Earlier quoted context omitted.

So what's the point of having let, then?

let declares a block-scoped variable, while var declares a function-scoped variable. Limiting a variable's scope can help avoid subtle and potentially annoying errors. For example, if you use a let variable inside an if block, it'll only be accessible by code inside the block. If you use var inside an if block, your variable will be visible to the entire function.

let also does some magic in for-loops, creating a new variable for each iteration, basically creating a closure.

It also throws and error if it's used before it's declared.

Let basically fix some minor issues that hard-bitten JavaScript developers have learned to avoid.

Post reply on HN