News for hackers. Stuff that matters.
Re:What’s New in ES2019 by halfmatthalfcat on Tuesday July 30, 2019 @07:41AM (#20563907)
Now if we could just get pattern matching[1] and optional chaining[2], that would really elevate things.

[1] https://github.com/tc39/proposal-pattern-matching

[2] https://github.com/tc39/proposal-optional-chaining

Re:What’s New in ES2019 by phpnode on Tuesday July 30, 2019 @08:18AM (#20564115)
Pattern matching is a really important feature but I strongly dislike that proposal because it feels like it introduces a bunch of single purpose syntax that's going to restrict the ability to evolve the language in future. It feels like it's an addon, not a holistic solution.

I would much, much rather that type annotation syntax gets standardised first, because it is comparatively easy to build pattern matching when that's in place but going the opposite direction is difficult. What is a type if not a pattern?

Re:What’s New in ES2019 by pas on Tuesday July 30, 2019 @09:25AM (#20564586)
It seems that only `when` and `->`is the new syntax, no? The arrow seems something that could be replaced with `=>`, but anyway, neither seems to be very restrictive with regards to future syntax. (After all they are only defined in a `case` context, so the can be reused for whatever future purpose outside.)

Plus it's a stage1 proposal, meaning it's far from serious.

Could you link the type annotation proposal, I can't find it.

Re:What’s New in ES2019 by snek on Tuesday July 30, 2019 @10:27AM (#20565094)
There is no type annotation proposal.
Re:What’s New in ES2019 by sdegutis on Tuesday July 30, 2019 @11:13AM (#20565558)
TypeScript is becoming the de facto type annotations proposal.
Re:What’s New in ES2019 by Roboprog on Tuesday July 30, 2019 @05:31PM (#20569406)
Let me know when (type inference of) partial function application and object literals are easy in Typescript and I’ll consider it.
Re:What’s New in ES2019 by sdegutis on Tuesday July 30, 2019 @06:10PM (#20569720)
Do you have a specific example of code that's hard to annotate in TypeScript? I've been using it for about a year without major issues (except somewhat slow compile times).
Re:What’s New in ES2019 by Roboprog on Wednesday July 31, 2019 @02:51PM (#20577089)
Re:What’s New in ES2019 by snek on Tuesday July 30, 2019 @10:26AM (#20565087)
In JS, the pattern is the type. That is the point of duck typing.
Re:What’s New in ES2019 by SomeOldThrow on Tuesday July 30, 2019 @04:28PM (#20568783)
> In JS, the pattern is the type.

How do you match against a `Buffer` pattern/type?

Re:What’s New in ES2019 by vimslayer on Wednesday July 31, 2019 @01:30AM (#20571907)
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 by SomeOldThrow on Wednesday July 31, 2019 @01:35AM (#20571921)
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 by cypressious on Tuesday July 30, 2019 @07:48AM (#20563953)
Optional chaining recently reached stage 3, the babel plugin is available and TS is going to adopt it for 3.7.0.
Re:What’s New in ES2019 by chriswwweb on Tuesday July 30, 2019 @08:04AM (#20564042)
Oh I didnt know about TS being so close to have it, that's great news

EDIT: here is the confirmation TS 3.7.0 got tagged: https://github.com/microsoft/TypeScript/issues/16#issuecomme...

EDIT 2: wow just noticed, that the issue ID is "16" and it has been open since Jul 15, 2014 (I guess: good things take time ... ;) )

Re:What’s New in ES2019 by johnkpaul on Tuesday July 30, 2019 @08:06AM (#20564051)
This is awesome and hopefully 2020 bound. The only thing I remember from my few months of looking into Groovy was the "elvis operator" and being very jealous of it.
Re:What’s New in ES2019 by Gene_Parmesan on Tuesday July 30, 2019 @10:47AM (#20565279)
I adore pattern matching when done well, but I'm sorry -- that syntax seems terrible and confusing. The use of `{ }` seems arbitrary. In JS braces are already used for both scope-delimiting and object literal notation; now they're going to have a third job? There has to be a better way.

I understand it's based on destructuring; the syntax still just doesn't work for me.

Re:What’s New in ES2019 by hajile on Tuesday July 30, 2019 @12:29PM (#20566444)
Ocaml, StandardML, F#, Erlang, and Rust all use that syntax for pattern matching. What other syntax would you propose to test values in a JS object?
Re:What’s New in ES2019 by chriswwweb on Tuesday July 30, 2019 @08:03AM (#20564035)
Yeah very excited about optional chaning, which few days ago got accepted to stage 3 "candidate", so just one more stage (stage 4 "finished"), I guess and hope it will be ready for ES 2020
Re:What’s New in ES2019 by k__ on Tuesday July 30, 2019 @02:42PM (#20567839)
Re:What’s New in ES2019 by snek on Tuesday July 30, 2019 @09:35AM (#20564664)
Optional chaining is stage 3, and major engines are actively implementing it.
Re:What’s New in ES2019 by tlrobinson on Tuesday July 30, 2019 @02:12PM (#20567545)
These two and decorators (including function/assignment decorators) are the top 3 on my wishlist.
Re:What’s New in ES2019 by Kiro on Tuesday July 30, 2019 @09:26AM (#20564595)
What's the point of pattern matching? Why not just a switch statement?
Re:What’s New in ES2019 by halfmatthalfcat on Tuesday July 30, 2019 @09:36AM (#20564677)
Switch pivots off of one value, pattern matching allows you to match on types, destructured values, conditional execution based on the existence (or lack thereof) of those values or types. It's much more flexible then switch (but arguably more complex).

See Scala[1] or Swifts[2]'s implementations.

[1] https://docs.scala-lang.org/tour/pattern-matching.html

[2] https://docs.swift.org/swift-book/ReferenceManual/Patterns.h...

Re:What’s New in ES2019 by codenirvana on Tuesday July 30, 2019 @05:15PM (#20569253)
Waiting for Optional Chaining. It's in Stage 3 already.
Re:What’s New in ES2019 by ehsankia on Tuesday July 30, 2019 @05:27PM (#20569375)
And this is why I love kotlin so much. It has all of these and so much more. Really excited to have .flat() and .flatMap() in ES2019, it's one of my favorite array feature in kotlin. Now just need something similar in python to avoid having to use itertools.chain or weird double comprehension.