Open gorosgobe opened 1 year ago
Thanks for putting this together! I highly suspect that the occurrence of prefix notation is so much lower in Kotlin is because of the de facto use of IDE tooling with refactoring suggestions. It's likely that Kotlin devs get a nudge to write in the more canonical form.
It's admittedly a little bit harder to do that with a language like JavaScript because anecdotally users don't always like being nudged into something that feels stylistic. That's often left for formatters and linters, but it's still a possibility.
Overall, the data shows that prefix negation is substantially more popular than infix negation across both languages, with Kotlin showing the biggest difference between prefix and infix forms.
This conclusion seems to be backwards? Based on the data in the table, it should read:
Overall, the data shows that infix negation is substantially more popular than prefix negation across both languages, with Kotlin showing the biggest difference between prefix and infix forms.
@Fayti1703 thanks for catching this, it has now been corrected!
During the Tokyo TC39 meeting, some committee members mentioned that they were skeptical that introducing a new way to negate
in
andinstanceof
expressions would help reduce the number of bugs in these expressions.I collected some data through Sourcegraph to see the popularity of infix negation (this proposal) versus prefix negation (current way of negating
in
andinstanceof
) in Kotlin and Python, which are the most popular languages using either of the syntax options (!
andnot
). If infix negation is more popular, then this would suggest that introducing infix negation through negatedin
andinstanceof
operators would indeed be a more popular option, and over time the number of bugs would reduce.not a in b
a not in b
not a in b
a not in b
not a is C
a is not C
not a is C
a is not C
!(a in b)
a !in b
!(a in b)
a !in b
!(a is C)
a !is C
!(a is C)
a !is C
Note: In Python,
not
has lower precedence thanin
andis
, so no parentheses are needed. In Kotlin, in contrast,!
has higher precedence, so parentheses are required.Overall, the data shows that infix negation is substantially more popular than prefix negation across both languages, with Kotlin showing the biggest difference between prefix and infix forms.