I wonder when we're gonna get bitwise operators. O...
# random
r
I wonder when we're gonna get bitwise operators. Or if it'll even happen
👍 3
e
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
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
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
All good points. I’ve added them to https://youtrack.jetbrains.com/issue/KT-1440
👍 6