Live data from Hacker News

What’s New in ES2019

blog.tildeloop.com

41–50 of 411 posts

Re: What’s New in ES2019

#41
post #38

Why did they create a flatMap method? What is wrong with .map(...).flat()? Can they improve the performance by combining it that much?

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.

Re: What’s New in ES2019

#42
post #24

Earlier quoted context omitted.

What’s wrong with var a = ...; a = a.project(); a = debug(a); a = a.eject();

That can’t show the programmer’s intent whether it is mutation (e.g. a = a + someNum) verses defining a new variable with different types (but has a similar meaning so has a same name) (e.g. someKindOfData = [...someKindOfData]) Rust allows this, and it really clears codes up. I don’t have to make up different identifiers for same data but different representations. (e.g. I would do the above code in JS as... someKin…

[deleted]

Re: What’s New in ES2019

#44
post #35

That Function.prototype.toString change is probably going to break some Angular.js code who relies on scanning function argument names for dependency injection.

It also requires that comments get stored and waste memory: previously just enough of the AST needed to be stored to be able to regenerate the JavaScript. You can't throw away the comments because you can't predict where code might do someVarHoldingAFunc.toString()

It seems like an unnecessary change - if the source needs to be accessed then get the source file.

Re: What’s New in ES2019

#45
post #38

Why did they create a flatMap method? What is wrong with .map(...).flat()? Can they improve the performance by combining it that much?

You could optimise either, I don't think that's the point. It's just a convenience that more clearly expresses the intent of the code where it's used. Imagine an example where the callback to map is quite long; seeing the flatMap identifier alerts you to the fact that the callback returns arrays, even before you start reading.

You'll find equivalents in all the JS utility libraries and most functional programming language standard libraries (and languages like Ruby with functional-ish subsets), so there's a lot of evidence that people who write code in that style like to have such a function available.

Re: What’s New in ES2019

#46
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…

I still don't understand why neither JSs var or let allow you to redefine the variable with the same name. I makes chaining things while debugging so much harder: let a = a.project(); let a = debug(a); let a = a.eject(); vs let a1 = a.project(); let a1d = debug(a1); let a2 = a1d.eject();

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 restrict the type of a declaration you can just assign a new value to it, place it in a small scope or use a chain.

Re: What’s New in ES2019

#48
post #31

Earlier quoted context omitted.

For me the worst is slice/splice.

Kind of stupid, but I imagine the 'p' in 'splice' being an axe that chops the array :D Works for me...

I think OP was saying slice returns a mutated copy while splice mutates in place.

Re: What’s New in ES2019

#49
post #8

That’s a surprisingly small amount of change. I’ll leave it to others to determine if that’s a good or bad thing.

Clojure too didn't change a lot. In these years of 'disruption' it feels odd. But it may just be that we forgot stability and maturity.

Existing Clojure APIs don't change, but Clojure adds a lot more than this each year. Look at spec, reducers, transducers &c

Re: What’s New in ES2019

#50
post #8

That’s a surprisingly small amount of change. I’ll leave it to others to determine if that’s a good or bad thing.

Technically most of this is not even language changes but simple changes to the standard apis. E.g. flatMap is something I've missed and worked around by implementing it myself a few times. Not a big deal and nice that they added it. In any case, I use typescript by default now and have converted most of the code I care about at this point. I think most of this improves typescript as well so; overall a good thing.

That's true for most of ecmascripts history - they tend to introduce convenience methods that people needed, built and relied on.

How much of ES5.5+ was guided by jQuery?

Post reply on HN