Skip to content
This repository has been archived by the owner on Jan 28, 2023. It is now read-only.

coordinate operator choice with optional-chaining proposal #9

Closed
tvald opened this issue Aug 8, 2017 · 19 comments
Closed

coordinate operator choice with optional-chaining proposal #9

tvald opened this issue Aug 8, 2017 · 19 comments

Comments

@tvald
Copy link

tvald commented Aug 8, 2017

Over in the optional-chaining proposal, there's been some discussion around how to accommodate the full set of possible/proposed shorthand operators for truthy-falsy and nullish behaviors. (link)

Copying a relevant table from over there:

base truthy/falsy nullish
coalesce x ? x : y x || y x ?| y (alt: x |? y)
guard x ? y : x x && y x ?& y (alt: x &? y)
chain x ? x.y : x - x??.y

Any opinions? All of these operations inhabit an adjacent space, so there should be some coordination in order to avoid multiple conflicting designs.

@Mouvedia
Copy link

Mouvedia commented Aug 8, 2017

If both the null guard and null coalesce are introduced in the same ECMAScript version, I vote for the couple ?| / ?&.

If for some reason one is more useful than the other and the other is being pushed back to another version, I'd say keep ?? which is shared by Swift, PHP 7 and C#.

@tvald
Copy link
Author

tvald commented Aug 8, 2017

There's a growing preference for using ??./??()/??[] as the optional-chaining operator. See tc39/proposal-optional-chaining#5

@Mouvedia
Copy link

Mouvedia commented Aug 9, 2017

@gisenberg would you mind changing the repo/proposal so that it covers both nullary-coalescing and nullary-guard?

@ljharb
Copy link
Member

ljharb commented Aug 9, 2017

We shouldn't add things just to fill in a table; what are the use cases for "guard"?

@tvald
Copy link
Author

tvald commented Aug 9, 2017

We shouldn't add things just to fill in a table; what are the use cases for "guard"?

discuss in #4

@gisenberg
Copy link
Member

In the interest of keeping proposals as small as possible (addressing "I don't want to commit to X if I only want Y"), I think that null guard would be best served in an independent proposal.

I'm currently championing both proposals, so the coordination tax is easy to manage. Unfortunately, the syntax choices in one proposal impact the other that makes it hard to present, as reviewers can't reason about the proposals independently when syntax is intertwined. This proposal + optional chaining will likely be merged in the near future.

@claudepache
Copy link

This proposal + optional chaining will likely be merged in the near future.

I am personally somewhat skeptical about the pertinence of merging, because the syntax is the only interdependent issue. Otherwise, the two proposals have each their distinctive issues and challenges (e.g., precedence for nullish-coalescing, short-circuiting for optional-chaining).

@gisenberg
Copy link
Member

@claudepache They have different concerns, but they are related enough that I don't think I can advance among the committee unless they are presented in the context of each other. For example, there's general support for ??. in optional chaining but only if null coalescing has a distinct token.

@hax
Copy link
Member

hax commented Mar 22, 2018

Whether or not two proposals merged, these operators should be landed together. And it seems there are not much semantic issues left in both proposals. The only big issues are syntax and operator precedences.

@hax
Copy link
Member

hax commented Mar 22, 2018

only if null coalescing has a distinct token.

What "distinct token" mean? Does that mean ??: ??| ??? are ruled out if use ??. for optional chaining?

@gisenberg
Copy link
Member

@hax Sorry, "distinct" was the wrong word to use there. What I meant was, there was general support for ??. assuming that null coalescing could land at another token that wasn't ?? that satisfied the committee.

@hax
Copy link
Member

hax commented Mar 22, 2018

@gisenberg I just confused, if use ??. we obviously can't use ?? for null coalescing... Sorry, maybe my English is too poor to understand what you mean...

@gisenberg
Copy link
Member

@hax Your understanding is correct. If optional chaining is using ??., then null coalescing must use another token that is not ??.

@hax
Copy link
Member

hax commented Mar 22, 2018

@gisenberg So I guess the situation in the meeting is, attendees think ?? is the best choice of null coalescing, but also prefer ??. for the optional chaining. Am I right?

@gisenberg
Copy link
Member

@hax That is correct.

@hax
Copy link
Member

hax commented Mar 22, 2018

@gisenberg Oops, we are just go back to the original point... This is really a tough work for you!

@gisenberg
Copy link
Member

@hax Yep! I sent an email your way if you're interested in discussing further.

@hax
Copy link
Member

hax commented Mar 22, 2018

@gisenberg Yes, I always glad to give a help for JavaScript community!

@ljharb
Copy link
Member

ljharb commented Jan 28, 2023

Closing, since this proposal is at stage 4, and the operators were indeed coordinated.

@ljharb ljharb closed this as completed Jan 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants