You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 ?. ba ?&[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”.
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:
Pros
?&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.Cons
?.in C#, Swift, CoffeeScript and Groovy, and&.in Ruby.)About the choice of ?&
?recalls that we are dealing with null/undefined, as this character is used in several languages for denoting an optional/nullable value or object.&recalls that the short-circuiting condition resemble the one of the&&operator (replacing “falsy” with “nullish”).?: “check for null”;&: “perform eventual short-circuiting”.