tc39 / proposal-optional-chaining

https://tc39.github.io/proposal-optional-chaining/
4.94k stars 75 forks source link

Post-operator question mark #114

Closed stuartpb closed 5 years ago

stuartpb commented 5 years ago

I looked at all the previous alternative syntax proposals, and none of them seem to propose using .?, [?, and (? as the chaining operators, as I proposed on WICG about three years ago.

Wouldn't this make more sense, as the only case where this overlaps currently valid syntax is the 1.?foo:bar case described in other issues that only propose variations of .? for the other two operators (which, as noted in those issues, is evitable by not allowing this syntax on numbers)?

ljharb commented 5 years ago

Hmm - it might be confusing whether obj[?foo] applies the ? to the object or to the foo variable?

claudepache commented 5 years ago

Mmh, I’m sure that someone somewhere proposed that syntax, and that I explained why I didn’t like it, but I cannot find it... But @ljharb expressed my main objection in fewer words than I would have been able to.

Also, someone proposed that in a past poll about preferred syntax, but the option wasn’t very popular...

jridgewell commented 5 years ago

Discussed in https://github.com/tc39/proposal-optional-chaining/issues/61

stuartpb commented 5 years ago

61 doesn't discuss .?, [?, and (? though - it discusses .?, .?[, and .?(.

The reason I think the former is superior to the latter (or ?., ?.[, and ?.( as are currently proposed) is because it doesn't introduce a . to the chained-index-and-call operators, which wouldn't have a . in their non-chained versions.

Zarel commented 5 years ago

[? is mentioned in https://github.com/tc39/proposal-optional-chaining/issues/61#issuecomment-390500224

Overall, the arguments in #61 (which are mostly about how ? makes more sense before . than after) apply equally well to [? and (?.

To be fair, you could make an argument that that's worth not having the weird dot in ?.[ and ?.( – but again, it was proposed in the poll and near-unanimously rejected, so I seriously doubt anyone would think it's worth revisiting after Stage 3.

claudepache commented 5 years ago

To be fair, you could make an argument that that's worth not having the weird dot in ?.[ and ?.( – but again, it was proposed in the poll and near-unanimously rejected, so I seriously doubt anyone would think it's worth revisiting after Stage 3.

Indeed.

Syntax has been discussed to death in the past, and we’ve reached rough consensus on the least bad option. I’m closing this issue in order to make clear that, as of now, the proposed amendment has about zero chance to be accepted, in absence of very strong and improbable reason. Thanks for your interest.