https://kotlinlang.org logo
#random
Title
# random
r

redrield

08/03/2017, 3:13 AM
I wonder when we're gonna get bitwise operators. Or if it'll even happen
👍 3
e

elizarov

08/03/2017, 4:10 AM
It would be great is you also share your use-cases. What kind of domain you are working in that requires a lot of bitwise operators? (code sample would be great, too)
r

redrield

08/03/2017, 5:59 AM
Wrote that message when I was writing some code to deserialize a special int type from a socket, but that code is ugly as all hell
The worst line, in my opinion is
out = out or (inByte and 0x7F) shl (bytes++ * 7)
It's just that the infix functions we have currently are less expressive of their usage, more verbose in their usage, and don't allow assignment operators, which ties into the second point
2
The fact that I can't at the very least do
out |=
is the worst part about having it this way, imo
And to the expressive point,
>>
, and
<<
give you an idea of what they do with the operators. Yet I can pretty much guarantee that no one who hasn't worked with this sort of code before, will be able to tell what
shl
does in that context without jumping to source to view documentation
n

napperley

08/03/2017, 11:00 AM
Extremely important to have the bitwise operators for embedded development since they are used regularly. If Kotlin is to cover embedded development (not the real-time performance related sub areas) via Kotlin Native then the operators need to be present.
1
e

elizarov

08/03/2017, 2:27 PM
All good points. I’ve added them to https://youtrack.jetbrains.com/issue/KT-1440
👍 6
7 Views