Javascript is such a mess, this proposal looks really bad, and the guys discussing it are saying things like: "we should make sure that this doesn't look like anything else, so that people who learn the language don't confuse match and switch..." There is also a lot of "we shouldn't break that" messages, and people reply with "oh we already screwed that up here and there, so it's fine"...
JavaScript Pattern Matching Proposal
61–70 of 254 posts
Re: JavaScript Pattern Matching Proposal
#62Stop using (nested) ternary operator's ! Use if-statements! if(val==1) var res = 1; if(val==2) var res = 2;
const var =
val == 1 ? 1 :
va1 == 2 ? 2 :
null;Re: JavaScript Pattern Matching Proposal
#63The definition bit looks like a function definition but behaves entirely differently. Why? Why not make it a constructor like everything else? People could look at it and be like "oh a match object" instead of wondering if you overloaded function.
The selectors look like json, only assignable. Again make it obvious.I mean we could even just make it json why not.
Re: JavaScript Pattern Matching Proposal
#64Isn't pattern matching interesting only in a strongly typed environment where the compiler can statically check that you are giving instructions for all possible cases?
Exhaustiveness checking is what elevates pattern matching to the other side of the expression problem, which is about getting feedback from the compiler to help you write programs.
Re: JavaScript Pattern Matching Proposal
#65Javascript is such a mess, this proposal looks really bad, and the guys discussing it are saying things like: "we should make sure that this doesn't look like anything else, so that people who learn the language don't confuse match and switch..." There is also a lot of "we shouldn't break that" messages, and people reply with "oh we already screwed that up here and there, so it's fine"...
Re: JavaScript Pattern Matching Proposal
#66Interestingly, the match construct is an expression, which I don't think JavaScript has m/any of. Perhaps they could retroactively make if/else expressions, if that doesn't break back-compat.
Re: JavaScript Pattern Matching Proposal
#67Isn't pattern matching interesting only in a strongly typed environment where the compiler can statically check that you are giving instructions for all possible cases?
Re: JavaScript Pattern Matching Proposal
#68Interestingly, the match construct is an expression, which I don't think JavaScript has m/any of. Perhaps they could retroactively make if/else expressions, if that doesn't break back-compat.
That would be really cool. This match feels a lot like Rust's which is good.
Re: JavaScript Pattern Matching Proposal
#69Earlier quoted context omitted.
It's been "trendy" since the 70's. It's more that more people have experience with it and realize that pattern matching is like conditional statements on steroids.
> It's been "trendy" since the 70's. It's been possible since the '70s but I've seen a lot more talking about it in the last 5-10 years.
Re: JavaScript Pattern Matching Proposal
#70Earlier quoted context omitted.
That would be really cool. This match feels a lot like Rust's which is good.
I would argue that it doesn't feel like JavaScript much which seems bad.