https://kotlinlang.org logo
#language-proposals
Title
# language-proposals
l

LastExceed

04/30/2020, 12:50 PM
Untitled.kt
s

spand

04/30/2020, 12:56 PM
Please read the channel purpose
Your questions are just fine for #general
l

LastExceed

04/30/2020, 12:57 PM
there, i fixed it. happy now?
r

Ruckus

04/30/2020, 1:26 PM
Cosmetically, I'd prefer
x ?- 7
l

LastExceed

04/30/2020, 1:26 PM
that's just code style
r

Ruckus

04/30/2020, 1:30 PM
Not necessarily.
x ?: 7
is valid.
x? : 7
is not.
l

LastExceed

04/30/2020, 1:31 PM
oh you're right, i forgot about that
but keep in mind that your proposal would introduce a new operator, whereas mine doesn't since
-
is just an infix function that directly translates to
.minus()
(which is why i'm wondering why it doesnt work already)
d

Dico

04/30/2020, 10:23 PM
It doesn't have to introduce a new operator? You can write
x ? .minus(...)
as well
I don't really like the idea though. Null pointer exceptions happen when you dot-qualify null. Therefore, the dot qualified expression is integral to the ?. notation to convey the intention. With arithmetic operators, the intention is not clear from the syntax at all.
d

Derek Peirce

05/01/2020, 3:48 AM
I agree that the operator syntax should be reserved for non-null values,
x?.minus(7)
reads just fine and
x?-7
will require a double-take no matter where the spaces go
2 Views