what are the chances we will be given the ability ...
# announcements
h
what are the chances we will be given the ability to add custom operators? i'm guessing low to impossible given the existence of infix
k
See scala for how this tends do go wrong.
h
is it mostly just a case of misuse? unreadable code?
k
m
Or look at SBT. Until you know it, the operators feel random.
h
do you think kotlin shouldn't employ features that can be used sloppily? i feel like it's a bit late for that with extension functions and properties.
i love kotlin because it can be written as to be supremely readable, and i think custom operators have the potential to improve that aspect, and i'm willing to see any feature capable of that, even if it can be greatly misused to the opposite effect
m
Of course not. Great code can be written in any language, just like terrible code can be written in any language. I’m happy with Kotlin’s overloaded limited operators. But yes, any feature, when used well, can improve things. So it comes down to the team…
1
h
honestly, one thing i'm most eager for is the further establishment of Kotlin codestyle, like how best to write chained scope functions, where if/else is appropriate to forego brackets, at what point should a single line property definition be split up, etc
m
chained scope style is definitely a biggie. Makes such a difference in reading if it’s the way ‘you’ expect it to be vs when it isn’t. I don’t think the IntelliJ formatter provides quite enough control over formatting of things like that, although I haven’t looked super close. Also, on topic of operators, I’m curious about some examples as it would appear you have some ideas already. I was very glad to see they allowed overriding the arithmetic operators, as there are many cases where being able to do that cleans up code while keeping it feeling ‘natural’.
h
One cool example is the
d
operator in D&D.
1d10+5
. I know infix does that, but I don't like the spaces. We could also create our own mathematical operators like a power operator
**
m
Hmmm. I suspect another reason would be the impact on the compiler. Parsing that
d
out makes parsing take longer. Kotlin is already slower than Java, and a lot of people complain about Scala’s compiler speed. If you use the language, you stop caring, or don’t notice, but when you’re first starting out…
It’s a tough call designing a language. Glad I’m not doing it 😉