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

Syntax: Use ?& (or anything else that correct the inconsistency between a?.b and a?.[b]) #34

Closed
claudepache opened this issue Sep 22, 2017 · 282 comments
Labels
alternative syntax past ideas and discussions about alternative syntaxes

Comments

@claudepache
Copy link
Collaborator

claudepache commented Sep 22, 2017

After careful consideration (see in particular #5), I think that the best syntax satisfying the difficult constraints we face (strong BC, consistency) is the following:

a ?& . b    // instead of   a ?. b
a ?& [ i ]  // instead of   a ?. [ i ]
a ?& ( x )  // instead of   a ?. ( x )

Pros

  • Complete consistency between the three syntactical forms.
  • Having a ?& token distinct from . is pedagogically better: One can picture the ?& token checking whether the LHS is null/undefined and performing short-circuiting if applicable, then the subsequent ., [ or ( token performing regular property access or function invocation.
  • Zero conflict/ambiguity in syntax with other features, zero parsing issue.

Cons

  • Somewhat more awkward to type.
  • Different from other languages. (However, it is reminiscent of both ?. in C#, Swift, CoffeeScript and Groovy, and &. in Ruby.)

About the choice of ?&

  • The ? recalls that we are dealing with null/undefined, as this character is used in several languages for denoting an optional/nullable value or object.
  • The & recalls that the short-circuiting condition resemble the one of the && operator (replacing “falsy” with “nullish”).
  • The order between those two chars is carefully designed: ?: “check for null”; &: “perform eventual short-circuiting”.
@madskonradsen
Copy link

Sounds like a well thought through proposal. I believe the syntax is much more readable than the initial proposed ?. syntax(which just seemed wrong when being followed by ( or [ ). Is ?? totally off the table because of the nullary coalescing proposal?

@samuelgoto
Copy link

samuelgoto commented Sep 22, 2017

I think this is the right direction too (I agree that the consistency argument is a solid one).

Can you walk us through the alternatives considered? In addition to ?? what else could be explored and why ?& is favorited? I saw (?) proposed earlier and for documenting sake it would be good to state its trade-offs (e.g. makes it confusing for humans with a function call).

I'm curious about ?? too, sounds like if we should be optimizing for something it should be reserving it for optional chaining rather than nullary coalescing (i.e. i'd expect to see way more ??. accessors than ?? nullary coalescing).

@tvald
Copy link

tvald commented Sep 22, 2017

Can you walk us through the alternatives considered?

There's a lot of discussion over in #5 about this, just search the page for ?&. Here's a short list of proposals from that thread:

?. - #5 (comment)
?? - #5 (comment)
?! - #5 (comment)
?: - #5 (comment)
|? - #5 (comment)
?& - #5 (comment)
?| - #5 (comment)

@claudepache
Copy link
Collaborator Author

I'm curious about ?? too, sounds like if we should be optimizing for something it should be reserving it for optional chaining rather than nullary coalescing (i.e. i'd expect to see way more ??. accessors than ?? nullary coalescing).

The main issue with ??, is that several other languages uses it for null-coalescing, which is a different feature. There is no possible confusion with ?&.

@Mouvedia
Copy link

@claudepache Would it be coupled with a ?| proposal? If not is it planned?

@ljharb
Copy link
Member

ljharb commented Sep 22, 2017

What would be the use case?

@Mouvedia
Copy link

What would be the use case?

null coalescing operator

@ljharb
Copy link
Member

ljharb commented Sep 22, 2017

That's already ??.

@saschanaz
Copy link

Do we even need . here? What does happen when it's just a?&b?

@ljharb
Copy link
Member

ljharb commented Sep 22, 2017

@saschanaz we would need all of ., [], and () to differentiate between optional member access, optional bracket access, and optional function invocation.

@saschanaz
Copy link

saschanaz commented Sep 22, 2017

@ljharb I think we can still differentiate them without the dot.

a ?& b
a ?& [ i ]
a ?& ( x )

@ljharb
Copy link
Member

ljharb commented Sep 22, 2017

@saschanaz that wouldn't be consistent; that way member access would be special and magic, and there'd be no explicit indication that it was using member access.

@Mouvedia
Copy link

PROS: "pedagogically better", "consistency"
CONS: ?. is already supported by Babel 7 β

@Mathspy
Copy link

Mathspy commented Sep 25, 2017

CONS: ?. is already supported by Babel 7 β

A major version bump to babel-plugin-transform-optional-chaining solves that. Now plugins don't all share same version with Babel afterall

@levithomason
Copy link

Yep, I think this is the best synthesis of all the proposals and issues raised thus far. Nicely done.

If you're doubting the syntax, please 1) review all the linked material 2) get a feel by writing some fake code with it and 3) imagine syntax highlighting. After doing this, I'm pretty convinced this is a done deal.

@claudepache
Copy link
Collaborator Author

@samuelgoto

Can you walk us through the alternatives considered? In addition to ?? what else could be explored and why ?& is favorited? I saw (?) proposed earlier and for documenting sake it would be good to state its trade-offs (e.g. makes it confusing for humans with a function call).

I’m not going to review in detail all suggestions I have seen (they are numerous); but I’ll try to give some criteria for comparing their merits: the ideal but impossible syntax is the one that meets all criteria.

Here they are, approximately ordered by importance. Naturally, the real ordering will depend on your sensibility.

  1. backward compatible (i.e., something that does not have currently another meaning, or at least that is so obscure that it is practically unused) — because this is a strong requirement for web browsers for reasons;
  2. reasonably easily parsable (e.g., not something that requires infinite lookahead);
  3. works for static and dynamic property accesses, and function calls, i.e. x.y, x[y], and x(y) — because I want to support the three cases;
  4. not used in mainstream languages for other purpose, e.g.: ?? or ?:
  5. uniform across the three syntactical cases;
  6. suggestive — for instance the symbol ? may suggest “something with null” or “something conditional”;
  7. has precedent in other languages, typically: ?.
  8. beautiful;
  9. easy to type.

Now looking at few proposed syntaxes:

  • ?. ?[ ?( — is almost perfect, but it doesn’t meet Criterion 2, which is very bad.
  • ?. ?.[ ?.( — which is the current state, fails at least Criterion 5. People reported that ?.[ and ?.(, fail Criteria 6 and 8 for them.
  • In general, Criterion 7 seems incompatible with the union of Criteria 1, 2, 3 and 5.
  • ?&. ?&[ ?&( — is what is proposed in this Issue. It meets objectively Criteria 1 to 5, and it fits well Criteria 6 in my opinion.
  • I’m leaving other proposals as exercise to the reader.

@damieng
Copy link

damieng commented Sep 26, 2017

Let's not underestimate the ongoing human cost of a new and different syntax.

?. is well known across languages for safe property access. People coming to the language will have to learn a new syntax and will probably get frustrated and go read threads like this to try and understand why. It adds up.

Is uniform access across three syntatical cases more important than precedent in other languages? (it's more about familiarity and being able to jump back and forth between languages).

I think either ?. ?.[ ?.( or ?. ?&[ ?&( would be better than ?&. ?&[ ?&(

Try visually scanning and typing the following two lines a few times to see how your eyes and fingers feel about the proposal;

customer?.address?.zip
customer?&.address?&.zip

(Typing ?. is incredibly easy on many layouts as the keys are adjacent. Throwing a far-away & between these two characters is painful)

@tvald
Copy link

tvald commented Sep 26, 2017

People coming to the language will have to learn a new syntax

Compared to other language quirks like truthy/falsy and ASI, the burden of learning a slightly different operator seems negligible.

I would rank uniform access as one of the most important qualities for this proposal, just below the parsing / compatibility requirements which rule out ?./?[/?( and ??./??[/??(.

@damieng
Copy link

damieng commented Sep 26, 2017

Why do you rank uniform access as more important than ease of use? (learning, typing)

@ljharb
Copy link
Member

ljharb commented Sep 26, 2017

Uniform access directly correlates to ease of use.

@jridgewell
Copy link
Member

jridgewell commented Sep 26, 2017

Why do you rank uniform access as more important than ease of use?

Uniform operators are inherent in ease of use. I don't have to think "is it ?&. or ?., or ?&[ or ?[".

and ??./??[/??(

Null coalescing isn't an accepted proposal yet, so ?? is still open. The proposed ?& actually makes the operators different, so that might need to be address (making ?? free again).

@claudepache
Copy link
Collaborator Author

@damieng While I understand some of your sentiments, I think that the following argument is not valid:

Is uniform access across three syntatical cases more important than precedent in other languages? (it's more about familiarity and being able to jump back and forth between languages).

I think either ?. ?.[ ?.( or ?. ?&[ ?&( would be better than ?&. ?&[ ?&(

It is strictly less worse to have two different syntaxes in two different languages, than two different syntaxes in the same language. In that regard, ?. ?&[ ?&( is a non-starter.

@meandmycode
Copy link

meandmycode commented Sep 26, 2017

I think it's come to a point where there is no great solution, it would be good to get an off the cuff idea of what developers are willing to concede to though (perhaps via a targeted twitter poll), one thing with customer?&.address?&.zip for me personally is that the amount of characters between the identifiers has started to pass the immediately obvious que's I'm used to seeing when traversing hierarchy.

And I feel the ampersand in there actually compounds that glanceable confidence, as historically the ampersand is used with joining individual statements, so at a glance I'm getting mixed messages of:

customer?.address?.zip and customer&&address&&zip

And it takes that bit longer to realise, I would hope that with better syntax highlighting and time this proves to be a a non-issue.

@damieng
Copy link

damieng commented Sep 26, 2017

Uniform access directly correlates to ease of use.

That's not true on it's own. It aids predictability but syntax can be both uniform and yet not easy to use if it's not short and accessible.

I would argue ?&. is not accessible. It's hard to both read and type nor is it used anywhere in code or written language as far as I know.

Maybe it's just my hands hating the sequence (neither left nor right want's to drop & between two keys next to each other). I also find myself typing &?. for whatever reason. It's possible that this is just me but it's also possible that this is going to affect millions of JavaScript developers.

@samuelgoto
Copy link

samuelgoto commented Sep 27, 2017

@claudepache 's bullet points are a great framework, thanks for putting that together. I don't think, however, ?& is necessarily the best trade-off between the weights/ranking of the bullet points.

I mentioned this live in the meeting, but just wanted to state here my intuition (I'll link to the notes too).

works for static and dynamic property accesses, and function calls, i.e. x.y, x[y], and x(y) —
because I want to support the three cases;

I don't think I generally rank criteria [3, 5] as high as @claudepache does.

Like it was pointed out earlier, property access is by far the most common use case compared to ()-calls and []-access (matches my intuition and the data that was collected too).

Given that there are no "perfect" solutions (e.g. ?., ?[] and ?()), I think it is a better trade-off to make the common use case super neat (a?.b) at the cost of not enabling (and cornering) the others (a?[b] and a?()).

I propose we:

  • avoid entirely the forms of accessing through []s and calls ()
  • we keep ?. for property access which is the most common use case

FWIW, this was proposed somewhere by somebody else too, I'll link it here.
FWIW2, waldemar seems to have brought up that this creates inconsistencies/incoherences, which weren't clear to the group and he is going to follow up in writing somewhere and I can report back here too.

@ljharb
Copy link
Member

ljharb commented Sep 27, 2017

If we use ?. for property access, imo that permanently blocks bracket and call access since ?[ and ?( won't work.

@samuelgoto
Copy link

samuelgoto commented Sep 27, 2017

that's correct and that's the trade-off that i think is worth taking to enable the more common form a?.b for property access.

see earlier in my response:

at the cost of not enabling (and cornering) the others (a?[b] and a?()).

@gisenberg
Copy link
Member

How about something like this?

For optional chaining:
??., ??[, ??(

Null coalescing could go from ?? to ?| to accommodate.

@jridgewell
Copy link
Member

jridgewell commented Sep 27, 2017

For optional chaining: ??., ??[, ??(
Null coalescing could go from ?? to ?| to accommodate.

I also proposed something similar: ??., ??[, and ??(, with ??: for null coalescing, which keeps the base operator the same for all 4 cases.

@jrista
Copy link

jrista commented Mar 13, 2018

I'm honestly concerned by the push towards ??./??: for these operators and am with Hax here. As mentioned, there are ergonomics issues there. Those are very heavy operators, they require typing numerous characters, and they stand out a lot in code.

To be frank and honest, I wouldn't want to write code that was riddled with heavy operators all over the place. Especially one that is so obvious. Is not part of the goal here to make coding more convenient, not less? If we boil it down, the most convenient approach here is ?./?()/?[]. This is terse and clean and blends nicely with the code. It's as simple as that. Anything other than that starts to become tedious and verbose, and with the dynamic nature of javascript, optional chaining will be heavily used.

I understand there are syntactical and parsing concerns to be addressed, hence the reason for alternative syntax proposals. But let's not lose sight of the programming and human aspect here. Who in their right mind wants to be pounding out heavy optional chaining operators all day long in their code?

In particular, consider the difficulty in typing these characters. One can simply hit period and be done with it. One MUST hit shift in order to type a question mark. Typing a backslash is even more difficult as one must contort their fingers to some degree in order to hit backslash off in the upper right side of the keyboard...of all the characters involved in the optional chaining operator, I find backslash to be one of the worst for this very reason. A colon also requires pressing shift, so if we did :? or something similar, one must have shift down for both characters, and the same goes for ?>. The more characters involved, the more complicated it becomes to actually type these operators out. Currently, ?. is a rather keyboard-friendly option. It may not be the most syntactically pretty, however it would be far more pleasant to type.

@jrista
Copy link

jrista commented Mar 13, 2018

Oh, I should note, ?& is maybe even worse than ?\ from a key location and typing standpoint. You either have to contort to use one hand to keep shift down while pressing both ? and &, or use two hands. I would say ?& and ?\ are far from ergonomic, and definitely not finger-friendly.

Try typing these:

some?&long?&object?&chain?&()
some?\long?\object?\chain?\()

See how enjoyable it is. It's difficult, not a pleasant way to spend the day. :\ Ugly as heck, too! In one case, you've got a logical operator buried in your chain, in the other you have an escape operator. This is NOT confusing as all getout?

The currently proposed operator, ?., is a natural extension of what we already do. We already separate object properties in a chain from each other with a period. Adding a question mark onto that to indicate the potential for undefined or null is a natural extension to what we already do, to our existing muscle memory, and it uses an easily accessed character. Please, let us not lose sight of the human aspect here.

@claudepache
Copy link
Collaborator Author

@jrista

If we boil it down, the most convenient approach here is ?./?()/?[].

To be clear: Consider that we cannot use it, due to bad interaction with the conditional (ternary) operator.

(A) True ambiguities when mixing conditional and optional chaining:

a?[b]?[c]:d
// a ? ([b]?[c]) : d /* or */
// (a?[b]) ? [c] : d

(B) Difficulty to parse efficiently. Moreover, we must prove that it is unambiguous:

x*a?[b]+c     //  (x * a?[b]) + c
x*a?[b]+c:d   //  (x * a) ? ([b] + c) : d

Alternatives have been explored and discussed since several months, and arguments have been made for all of them. At this point, we’ll most probably retain one of the two following options:

  • ?.?.[]?.()— and ?? for null-coalescing
  • ??.??[]??() — and ??: for null-coalescing

@ljharb
Copy link
Member

ljharb commented Mar 13, 2018

Are you really writing code that's riddled with maybe-nullish property lookup, such that ??. would riddle your code in a way that ?. wouldn't? That seems a bit hyperbolic.

@FranklinYu
Copy link

Anyone sharing a pointer/post/comment about why &. won’t work? I think this obvious choice should have been discussed, but searching is not for punctuations…

@jrista
Copy link

jrista commented Mar 13, 2018

@ljharb It really depends on the kind of application you are developing. Highly dynamic code can often involve more optional properties and null coalescence.

@ljharb
Copy link
Member

ljharb commented Mar 13, 2018

@jrista can you share a non-contrived example with ??. that you think would be ugly where the same example with ?. would not be?

@jrista
Copy link

jrista commented Mar 13, 2018

@claudepache Certainly. I understand the reasons why just a question mark alone is non-viable. I noted that in my previous post. I am just bringing it up to be clear that there is a human aspect here, and the farther we deviate from that ideal, just using a single question mark to denote optionality/two for null coalesce, takes us farther and farther from the most usable/typable proposal.

@FranklinYu
Copy link

@jrista You may add this to #51 to see whether anyone shares your opinion:

?., ?[ and ?( and let parser (including browser) and transpiler suffer from halting problem

@Tiedye
Copy link

Tiedye commented Mar 13, 2018

@FranklinYu There's been a moderate amount of discussion of &. on this thread, after a brief search here are some of the reasons against:
#34 (comment)
#34 (comment)
#34 (comment)

@jrista
Copy link

jrista commented Mar 13, 2018

@FranklinYu: I've been in that thread. I believe there is overwhelming support for ?./?? with the total rank (accounting for votes against) being 158. There is underwhelming support for ??./??: with the total rank (accounting for votes against) being -20. shrug

@hax
Copy link
Member

hax commented Mar 13, 2018

I want to repeat again:

??. + ??: is worse than all other alternatives (eg.?& or ?>) in three important aspect:

  1. It dismiss the usage of ?? for nullish coalescing which is very good for learning.
  2. a??(b) will have very different semantics in this proposal with all other languages which have ?? token. This will be a disaster for full-stack engineers who use C#/Swift/PHP/Dart... Even linter can not save your ass, because you can't enforce all other languages also use same coding style, and when you are reading code on github, there is no linter.
  3. a??.b visually too close to a??:b which very error-prone. Note, space-infix-ops rule is not in eslint:recommended. Even you enable space-infix-ops it will not warn a ??. b because it does not warn a . b currently. So a ??. b will visually too close to a ??: b and no linter rule can help you.

@js-choi
Copy link

js-choi commented Mar 13, 2018

Not that I think it might be the best idea, but has property ??. + coalescing ??? been floated at all as an idea yet? I haven’t seen it yet mentioned and it might be worth considering. After all, ??. and ??? might be more visually distinguishable than ??. and ??:. Don’t really know.

@hax
Copy link
Member

hax commented Mar 14, 2018

@js-choi ??? can solve point 3 in my last comment, but not point 1 and 2. Especially point 2 is very fatal.

@ljharb
Copy link
Member

ljharb commented Mar 14, 2018

@hax It’s only fatal if you believe the majority of JS programmers in the future will come from, or will even have used, other languages. I suspect that over time, the majority of JS programmers will have only ever used JS, or JS will be their first language; if that is true, then JS will define what things mean, not other languages.

@claudepache
Copy link
Collaborator Author

claudepache commented Mar 14, 2018

@hax You are overestimating the confusion that would occur when having ?? meaning different things in JS and in <language X>.

I use regularly, and even concomitantly, two languages that have different and incompatible use of the dot, namely PHP (string concatenation) and JavaScript (property access). It was far from fatal to my programming experience: the few times I have attempted to use the dot for string concatenation in JS, the outcome was buggy enough for me to realise my mistake quickly. That said I am open to hear horror stories that had resulted from such a situation...

A point to note, and that will greatly help to mitigate the possible confusion, is that it is common style to surround the null coalescing operator with spaces, and yet a space-isolated ?? will be a syntax error in JS. For the rest, the semantical difference of ??(x) between JS and <language X> will be severe enough so that it’ll rarely go unnoticed.

@hax
Copy link
Member

hax commented Mar 14, 2018

@ljharb

My personal experiences:

  1. My company is one of the biggest craigslist-like service provider in China. 80% programmers can read/write JS codes, 30%+ programmers mainly use JS in their work, but none of them only read/write JS. It's very common that a front-end engineer who use JS and a server-side engineer who use PHP work together and read/review each's code. Our app team use React Native so they must use both Swift/JS or Kotlin/JS. And I don't see any possibility our technical stack can become to using any sole programming language in near future.
  2. I gave many speeches in tech conferences. Some like JSConf China are all JS guys. Some like QCon are multi-domain conf that you will find users from different language communities. When I gave JavaScript - The World's Best Programming Language talk in ShenJS (JSConf China 2015), I did a investigation in the conference hall, at least 25% audiences show their love to other programming languages. (most love Python and Ruby, but also some prefer Java/C# or other languages.) When I gave the same titled JavaScript - The World's Best Programming Language talk in the programming language track of QConShanghai 2015, at least half audiences were from other languages, and there were speakers of C#/C++/Go/Python/Haskell/Lisp in the same room 😜. It's obviously to me there are many programmers take interest in JS and may have a try in some cases, but I don't think they would abandon their first languages.

So whether I agree or not agree "over time, the majority of JS programmers will have only ever used JS", I don't think it's acceptable to ignore the feelings of full stacks. And it will add pain to the programmers who mainly use JS but also other languages, and it will add a block to the programmers who use other language but try to use both JS and their first languages.

@hax
Copy link
Member

hax commented Mar 14, 2018

You are overestimating the confusion that would occur when having ?? meaning different things in JS and in <language X>.

While I see you are underestimating the confusion and possible accident.

the few times I have attempted to use the dot for string concatenation in JS, the outcome was buggy enough for me to realise my mistake quickly. That said I am open to hear horror stories that had resulted from such a situation...

This is a very good example. The key point is: the outcome must be buggy enough for you to realise the mistake quickly.

But even PHP dot problem is not buggy enough. I happen to have some accident reports caused by it in my last company !

The buggy code can be simplified to <p title="<?=$obj.prop?>"... while you really want $obj->prop

Here prop would be treat as constant and if no such constant, PHP would generate Notice. Normally you will see the notice in the page, but in this case you will not see it because the notice message is in the title attribute. Another even worse case is, we have a global defined constant PROP in the form of define('PROP', value, true); which is case-insensitive, so there is no notice at all !

You may argue, the coder should check whether the output is correct! I definitely agree with you, but people just make mistakes.

Note, as a good tech team, we even have tools and process to protect us. But they all failed because:

  1. We have linter for our PHP source code which enforce spaces around ., but unfortunately below code are emitted by a template engine which embed PHP expressions, and there is no linter for the template syntax in that time, and we can't apply PHP linter to emitted codes because it's basically not source code but very like compressed js.
  2. We also have a test team and test environment. And they really checked the output. But PHP notice output was suppressed on test environment just like production environment. So the tester didn't find there is a PHP notice. And the tester saw the output "name" because the code is $user.name and PHP guess you want to output "name" if there is no constant named name😂 . The tester thought "name" as a username of the test users in the test db. She complained to a colleague we should use a much real name in test db, but didn't realize it's a code bug.

After that, we finally added a hard-coded syntax check for the template to deal with the common issues. The interesting thing is, once a time, a newbie just wrote $a . b when he really mean $a->b, he misunderstand the warning of the linter which told him you should add spaces around . . Fortunately, his reviewer found the issue. So we changed the warning message to "Think again! You may mean $a->b !!"

Even we didn't have such accident later, we can't stop wasting time on accidently write it and fix it when coding.

It's too late to blame PHP using dot for a very different semantic (it come from perl, and perl6 just fix it by use ~ replace .) and its weird error-tolerant behavior, but I hope my accident reports can help you understand the situations. Though I have no accident reports from misunderstanding of a??(b + c) or a ??. b being misread as a ??: b now, I'm very confident someone would finally be trapped.

A point to note, and that will greatly help to mitigate the possible confusion, is that it is common style to surround the null coalescing operator with spaces, and yet a space-isolated ?? will be a syntax error in JS. For the rest, the semantical difference of ??(x) between JS and will be severe enough so that it’ll rarely go unnoticed.

You are assume other languages all adopt space around style for ?? and can enforce it everywhere. Even this was true, you could find the similar failures in my accident reports.

And it can not solve a ??. b being misread as a ??: b or versa. It's impossible to make a ??. b a invalid syntax, and I think linter unlikely could treat a ??. b or a . b as bad coding style.

@Lokdei
Copy link

Lokdei commented May 20, 2018

How about we keep ??. ??( ??[, as it is easy readable in any option for optional chaining.
And for null coalescing we introduce a new and better token, in which I propose ?=

?= explained
We keep the question mark indication the optional path
The equals sign is already used for assignment, and that would make it an easy mental bridge for the null coalescing operation. A user would expect what it does.

This new sign remains read- and writable albeit not as easy as ??.

@ljharb
Copy link
Member

ljharb commented May 20, 2018

If it has an equals sign, a user will only expect one of two things: assignment for one equals, and comparison for more.

@lukescott
Copy link

lukescott commented Jul 25, 2018

I don't have a problem with ?. at all. Swift allows ?( and ?[ without the extra ., but I know that isn't possible in JS, hence the extra ..

The purpose of ?. is to reduce crazy && property chains. ?. gets us most of the way there. For function calls, is there anything wrong with an if(){}? Can ?.( and ?.[ just be dropped entirely?

@lehni
Copy link

lehni commented Jul 25, 2018

@lukescott function calls are perhaps debatable (although I have regular use for them in a stage-1 based project that I work on), but I don't think ?.[ should be dropped. I see ?.( as a nice side effect of solving ?.[. Not solving ?.[ looks to me like adding an incomplete feature to the language. why should one form of property access support optional chaining and not the other?

@ljharb
Copy link
Member

ljharb commented Jul 25, 2018

@lukescott bracket access can never be dropped, no - not just for computed property access, but for Symbols, which can't be done with dot access. Without that symmetry between bracket and dot, the feature makes no sense.

@claudepache claudepache added the alternative syntax past ideas and discussions about alternative syntaxes label Jun 9, 2019
sendilkumarn pushed a commit to sendilkumarn/proposal-optional-chaining that referenced this issue Jun 22, 2019
Clarify variable names and separation in examples
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
alternative syntax past ideas and discussions about alternative syntaxes
Projects
None yet
Development

No branches or pull requests