Why cant I format my bitewise ors to be on new lin...
# getting-started
u
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
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)
}
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
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
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
oh the parenthesis works, nice, I can live with that