Why cant I format my bitewise ors to be on new lines?
Copy code
bytes[0].toInt() shl 24 or (bytes[1].toInt() and 0xFF shl 16) or (bytes[2].toInt() and 0xFF shl 8) or (bytes[3].toInt() and 0xFF);
any sane person would write it alteast as
Copy code
fun byteArrayToInt(bytes: ByteArray): Int {
return bytes[0].toInt() shl 24
or (bytes[1].toInt() and 0xFF shl 16)
or (bytes[2].toInt() and 0xFF shl 8)
or (bytes[3].toInt() and 0xFF);
}
s
Shawn
01/17/2019, 5:24 PM
are you particular opposed to keeping the `or`s on the preceding line?
Copy code
fun byteArrayToInt(bytes: ByteArray): Int {
return bytes[0].toInt() shl 24 or
(bytes[1].toInt() and 0xFF shl 16) or
(bytes[2].toInt() and 0xFF shl 8) or
(bytes[3].toInt() and 0xFF)
}
Shawn
01/17/2019, 5:25 PM
or just using an extra set of parens?
Copy code
fun byteArrayToInt(bytes: ByteArray): Int {
return (bytes[0].toInt() shl 24
or (bytes[1].toInt() and 0xFF shl 16)
or (bytes[2].toInt() and 0xFF shl 8)
or (bytes[3].toInt() and 0xFF))
}
u
ursus
01/17/2019, 5:25 PM
yea I noticed newlining after or works, but im used to my whole life from java to put operator first thing on the new line
s
Shawn
01/17/2019, 5:26 PM
the problem is that
bytes[0].toInt() shl 24
is a complete statement and the compiler doesn’t know not to interpret a
SEMI
after
u
ursus
01/17/2019, 5:26 PM
oh the parenthesis works, nice, I can live with that