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

Null Propagation #78

Open
chicoxyzzy opened this issue Feb 3, 2017 · 4 comments
Open

Null Propagation #78

chicoxyzzy opened this issue Feb 3, 2017 · 4 comments

Comments

@chicoxyzzy
Copy link
Member

chicoxyzzy commented Feb 3, 2017

Null Propagation was promoted to stage 1 on January meeting. How should this work with private fields? AFAIU private properties are statically resoled so I suppose that something like a?.#b should be an early Syntax Error?

cc @gisenberg

@bakkot
Copy link
Contributor

bakkot commented Feb 3, 2017

As spec'd (with the caveat that it wouldn't match the grammar at all unless something was changed), a?.#b would differ from a.#b only in that if a is undefined or null then no error is thrown in the former case. I expect that would cause more confusion than it would prevent, so yeah, I think this should be a Syntax Error.

(Also, that would later allow us to redefine a?.#b to be undefined instead of throwing when a lacks a #b field, which would be kind of neat. Although maybe also too confusing to be worthwhile.)

@littledan
Copy link
Member

@bakkot makes a reasonable argument that this feature is relatively complicated and confusing, and it's harder to see the use case than ordinary null propagation. However, syntactically, this works out just fine: a?.#b is a clean composition of the two features. And that's not the case with some alternatives, such as a.?b, for null propagation syntax. Let's keep an eye on the interaction between these features--even if we have semantic reasons for not wanting to add the combination now, it's nice that the current proposals are compatible in this way.

@arcanis
Copy link

arcanis commented Mar 7, 2017

Btw, what was the rational regarding the use of the # character? I find the .# sequence a bit hard to type, since it requires a combo key (I'm on an azerty keyboard, one has to press Alt Gr+3). If possible, I'd prefer something like foo.*bar or foo.:bar. My two cents.

@littledan
Copy link
Member

The current proposal remains .#.

Sorry, I (personally) wasn't thinking about non-US keyboards with this proposal; in American keyboards, # doesn't require pressing Alt Gr.

However, given that, on a French keyboard, { and } are Alt Gr + number bar key combinations, it seems like the ship has already sailed on JS requiring these keys.

Leaving keyboard layouts aside, * already has a couple meanings (yield* and multiplication), and : also has a couple (property definition, labels, and in many compile-to-JS languages, type definitions), so overloading another seems risky in terms of promoting understanding. They also cause issues when taking the short form into account.

For now, I'd like to stick with .#.

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

4 participants