-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Could we re-evaluate what our "must-haves" are? #305
Comments
There are a lot of places an Similarly, it's definitely a requirement to have a way to apply arbitrary an JS rubric, otherwise it won't be possible to fully replace
i'm not sure why syntax highlighting wouldn't completely address this concern; it works fine for template literals in which any arbitrary JS could seemingly be nested?
|
Right, I suppose this may make
Sorry, what do you mean here?
I don't think this is serving to correct anything I was meaning to express though... 😅 |
I mean that I want to apply arbitrary logic to decide if something matches or not. Not every test is a simple one-argument predicate, nor something that patterns necessarily cover. Think of it like an escape hatch. |
Certainly, but I think that's still upheld by having |
Somewhat - guards may need to utilize bindings from a pattern, and in deeply nested locations, so it's quite helpful to have them as patterns themselves. |
I like the reductions proposed in this thread. |
I share the concerns that Ross raises here. I'd love to see the champions present on why a Python style In particular, I think |
When we tried to propose this without
Python's rejection of (That said, Python is one of the languages that lacks the ability to both bind and further test a sub-value, so an For For the spelling of |
Some addition (as I understand), because they think pattern syntaxes are too much, but only can be used in the |
It's so easy to get carried away with a pattern matching proposal, and I fear we're doing so again in the latest rewrite. Even though the intention was to increase comprehensibility by having "layers" to the proposal, I feel like we've instead ended up in a place where the proposal is harder to reason about, due to how a few of its pieces interact.
To start from some more positive territory:
I do want JavaScript to have a
match
statement and I think many of our proposed patterns are looking spiffy (objects, arrays, primitives, etc.)!While it might trip me up a little that
when foo:
isn't an unconditional match, I can certainly appreciate explicitvar
/let
/const
as a JS-y approach to bindings (and it's super comforting to see that Dart did similarly!).Other folks may have strong opinions about regexes and custom matchers, but I'll happily stand aside from those particular debates (and accordingly not mention them at all here 😄).
My discomfort has to do with three parts in particular:
is
,and
, andif
patterns.That said, it's not really any one of these pieces on its own that's the core issue:
I get that
if (x is { foo: Number })
would be neat to have. Do I think we should postpone it as Python did? Oh yes, definitely. But it's a reasonable thing for JS to have in the long run.or
is certainly a must-have (since we can't be "a betterswitch
" if we can't join multiple cases together), butand
is not—the thing we unequivocally need is a way to conjoin a binding with another subpattern, yet this is ironically the place whereand
feels like a confusing word choice. I would personally favor respelling that while following Python's lead in rejectingand
(andnot
), in the interest of encouraging users to keep patterns simple.Case in point, I can't help but feel that
if
patterns came from a line of thinking like, "Hey, now that we canand
whatever we want to... 😈". Make no mistake, I think this is a bad idea and that we should stick to prior art; however, I will admit that "when if
looks yucky!" on its own wouldn't be a very strong argument against it. 😅The real crux of my discomfort is the interplay between these.
As such, there are multiple facets to it and various ways that it could be alleviated:
Having this proposal be not just a
match
statement but also anis
expression means we now need to consider how patterns play with every other aspect of the language, which is incredibly challenging to reason about! Sticking to amatch
statement gives us freedom to do certain novel things within the confines of those braces—things like, say,and
andif
patterns!—so we might viewis
itself as a misstep. Still, Jordan argued that we'd want it sooner or later anyway, and I myself just admitted that the basic use case is pretty neat...so let's instead consider what's making me wish thatis
were something that "isn't".Above all, the idea that
if (...)
could exist as two different constructs in adjacent contexts feels to me like a threat to the language itself. I don't want to live in a world where this is valid code:Whether or not this can be fleshed out into "good" code, the issue I want to highlight is that we could no longer be certain at a glance what construct
if (...)
is when scanning code. Some ways this could be alleviated:if
as a guard instead of a pattern and exclude guards fromis
if
is { ... }
for clear visual delineationSimilarly, having all of
or
/and
/not
available for use right alongside||
/&&
/!
feels like we're bifurcating boolean expressions. I think Dart provides some really interesting food for thought here—they do haveand
patterns (spelled&&
), but instead of a fully flexibleis
expression, they just have anif
-case
statement. I think I'd feel way more comfortable withis
if it were specificallyif
-is
! As such, possible alleviations include:if
-is
statement and not a general-useif
expressionand
/not
(while respelling thelet x and <pattern>
case)is { ... }
for clear visual delineationAnyway, I hope this serves as a clearer expression of my concerns. (I'm breathing much easier just having written it!) I understand that we're all coming at this from differing philosophies, and I don't expect everyone to suddenly agree to postponing
is
, droppingand
, turningif
patterns back into guards. I would just like us to take stock of which pieces are the most important and have a calm discussion about mitigating their compound effects. 🙇The text was updated successfully, but these errors were encountered: