ummm, I didn't mean this code to be this rude
# compose-desktop
k
ummm, I didn't mean this code to be this rude
😂 7
👏🏼 2
👏 2
😆 2
e
ULongArray(3) { 0u.inv().toULong() }
is short and less "magical", maybe
k
In here I want to say that the mask preserves all bits of alpha, red, green and blue channels. So the shorter version loses that "message"
e
~0U
is a very typical way to express that in C, and
0u.inv()
is the analogue in Kotlin, plus
.toULong()
because no implicit conversions. but ymmv I guess
k
Bitmasks like this have a very clear meaning in working with ARGB colors.
0u.inv()
is an unnecessary distraction when you read such code
I don't need this to be clever. I need this to be readable.
e
with 0u.inv() I immediately know it's 32 bits while with 0xFFFFFFFFu I have to count. I can see your opinion, I just don't agree with it
m
Yeah, with 0xFFFFFFFFu you have to go through every character to see if all are Fs or if there is some subtle change. I have seen a color mask that goes like 0xEFFFFFFF (it was used encode color into 32bit float).
d
I think
0b000000000000000000000000000000011111111111111111111111111111111u
is more readable tbh. 🧌
p
0xFF_FF_FF_FFu
? 😛
e
Copy code
>>> StringBuilder("0b000000000000000000000000000000011111111111111111111111111111111u").apply { var c = 0; for (i in 3..64) insert(i + c, String(CharArray(Random.nextInt(4).also { c += it }) { '_' })) }.toString()
res0: kotlin.String = 0b00__0___0___0___0___0_0_0___0__00_0_00___000_0___00_0___00___0___00___0_0__0___011_11_1___1__1_11_1__1___1___1_1_1_1111__1_1_1__1___1_11__1_11_1___1__1u
>>> 0b00__0___0___0___0___0_0_0___0__00_0_00___000_0___00_0___00___0___00___0_0__0___011_11_1___1__1_11_1__1___1___1_1_1_1111__1_1_1__1___1_11__1_11_1___1__1u == 0xffffffffu
res1: Boolean = true
TIL: Kotlin allows for any size groupings separated by any number of underscores