Why `y` for bytes? I skimmed the linked JDK propos...
# language-proposals
k
Why
y
for bytes? I skimmed the linked JDK proposal, couldn't really find any justification there either.
r
I'm assuming beacause
b
causes issues (see above) and
y
is the next letter in
byte
👍 3
i
Exactly, for hex literals, e.g.
val b = 0xBy // Byte (11)
k
Yup, I got why `b`wouldn't work but couldn't figure out where the
y
came from...
i
Ah. I don't really have a horse in the which-letter-for-byte-literals race. Another possibility is 't/T', as it's the next hard consonant in byte.
r
Or we could go the rust route and use
i8
and
u8
👎 1
f
This might be my frenchness coming through, but I'd prefer 'o' (octet) for bytes rather than 'y' (although this might get confusing for hex
0x2o
)
r
Especially if upercase is also allowed
0x2O
👍 2
f
yup
i
https://kotlinlang.slack.com/archives/C0B9K7EP2/p1517943207000786?thread_ts=1517938178.000015&cid=C0B9K7EP2 Rust's scheme is concise and consistent, but I don't think it's an option if there's a desire to extend the current syntax rather than replace it, and/or maintain parity with Java.
2
r
Good point
b
i8
and
u8
are currently valid names for variables, and could easily make existing code not compile. Despite my distaste for it, @ianbrandt’s ideas are consistent and non-breaking
👍 2
m
C# 7.0 uses
0b
for binary literals, and
0x
for hex literals. They are signed by default. The
u
suffix is used for unsigned,
l
for long, and
ul
for ulong. What issues would
b
cause in Kotlin? I looked through the previous thread and didn't see the explanation.
r
Is
0x1b
supposed to be a byte value of 1, or an int value of 27?
m
Why would it be a byte value of 1?
0x
denotes hex, and
1B
is 27 in hex.
r
because the idea was appending
b
to a number specified it as a byte. That can't work because it would make hex literals ambiguous (i.e. you couldn't declare hex byte literals).
Copy code
val a1 = 1  // (Int) 1
val a2 = 1b // (Byte) 1
val a3 = 0x1  // (Int) 1
val a4 = 0x1b  // Is this (Int) 27 or (Byte) 1?
If
y
were used, all of the above would be unambiguous
Copy code
val a1 = 1  // (Int) 1
val a2 = 1y // (Byte) 1
val a3 = 0x1  // (Int) 1
val a4 = 0x1b  // (Int) 27
val a5 = 0x1y  // (Byte) 1
val a6 = 0x1by  // (Byte) 27
👍 1
j
I don't see why the language syntax needs to be more complicated when this can just be hinted to the compiler by using a type annotation