ianbrandt
02/06/2018, 12:11 AMvar i = 0i
for integers then?", I'll quote David Sedaris, and say that hopefully we can all, "...denounce the very idea as grotesque, and unrealistic." 😉)
var bool = false // Boolean
var b = 0b // Byte. Does not compile. Has to be "= 0.toByte()", or "var b: Byte = 0".
var c = 'c' // Char
var s = 0s // Short. As with Byte, does not compile.
var i = 0 // Int
var l = 0L // Long. Lowercase 'l' not supported.
var f = 0.0f // Float. 'F' also supported.
var d = 0.0d // Double. Does not compile, as 'd/D' not supported.
ianbrandt
02/06/2018, 4:41 PMvar bool = false // Boolean
var b = 0y // Byte. Uppercase 'Y' also supported.
var hb = 0x0y // Byte (hex)
var ub = 0uy // UByte. Uppercase 'U' also supported.
var uhb = 0x0uy // UByte
var c = 'c' // Char
var s = 0s // Short. Uppercase 'S' also supported.
var hs = 0x0s // Short (hex)
var us = 0us // UShort
var uhs = 0x0us // UShort (hex)
var i = 0 // Int
var hi = 0x0 // Int (hex)
var ui = 0u // UInt
var uhi = 0x0u // UInt (hex)
var l = 0L // Long. Lowercase 'l' also supported.
var hl = 0x0L // Long (hex)
var ul = 0UL // ULong. Lowercase 'u' also supported.
var uhl = 0x0UL // ULong (hex)
var f = 0.0f // Float. Uppercase 'F' also supported.
var d = 0.0d // Double. Uppercase 'D' also supported.
So, the master list is: y/Y, uy/UY, s/S, us/US, u/U, l/L, ul/UL, f/F, d/D.gildor
02/06/2018, 11:44 PMbenleggiero
02/07/2018, 2:48 AMianbrandt
02/07/2018, 4:16 AMbenleggiero
02/07/2018, 5:09 AMval n: Double = 12
is 12.0
? Why is val m = 6 as Byte
bad but takeByte(6)
OK? There are better refinements to Kotlin’s number literal system than appending cryptic single-character typecodes.
The following point has nothing to do with this proposal, but while I’m ranting about Kotlin types, why do we still call them Byte
, Short
, Int
, Long
, Float
, and Double
? How is that easier/more natural/better than Int8
, Int16
, Int32
, Int64
, Float32
, and Float64
? Then, we could let Int
and Float
be aliases for the numbers in the system’s native word size, which should make things better in general (fewer overflows, some operations faster, etc.)gildor
02/07/2018, 5:19 AMgildor
02/07/2018, 5:20 AMgildor
02/07/2018, 5:21 AMgildor
02/07/2018, 5:27 AMcryptic single-character typecodesType literals already here, we have
F
and L
and we have exponential notation: 42e10
, and new type literals just addition to avoid long type declaration, especially with unsigned typesbenleggiero
02/07/2018, 5:58 AMIt’s just namingYeah, and I dislike it. Opinions 😛 I love that in Kotlin I can ignore them: https://github.com/BlueHuskyStudios/Blue-Base/blob/master/JVM/src/org/bh/tools/base/abstraction/Abstracted%20Number%20Types.kt
Don’t need byte and shortI agree! In my profession, I use Swift’s
Int
, and in my hobby I use my own Integer
(a typealias
in the above link). Int
automagically matches the bitwidth of the target architecture, and I’d like to do that one day with my Integer
.
Not fixed size is dangerousI disagree. In fact, its safer in my experience. It means slightly better performance for free, longer arrays on wider architectures, and near-free adoption of new architectures. In my head, JVM and JS are ‘architectures’ just like x86 and ARM64. So, though the JVM’s native width is always 32, so is x86. In my #multiplatform project, I don’t need to worry about juggling things (theoretically, unfortunately, in Kotlin; practically, though, in Swift).
we haveI don’t likeandF
and we have exponential notation:L
42e10
F
and L
and think they should go away, too. I enjoy exponentiation in a literal because it is very useful for writing functions that are heavy on the maths.
I already don’t like seeing 10l
and having to pause to figure out if it’s 101
or 10L
. I don’t enjoy the idea of seeing 0b10l + 5BS - 0xADEU
and taking several seconds to figure out what’s really going on thereianbrandt
02/09/2018, 6:30 PMvar bool = false // Boolean
var b: Byte = 0
var hb: Byte = 0x0
var ub: UByte = 0
var uhb: UByte = 0x0
var c = 'c' // Char
var s: Short = 0
var hs: Short = 0x0
var us: UShort = 0
var uhs: UShort = 0x0
var i = 0 // Int
var hi = 0x0 // Int
var ui: UInt = 0
var uhi: UInt = 0x0
var l: Long = 0
var hl: Long = 0x0
var ul: ULong = 0
var uhl: ULong = 0x0
var f: Float = 0.0
var d = 0.0 // Double
ianbrandt
02/09/2018, 6:44 PMbenleggiero
02/10/2018, 9:35 PMfun parseHttpStatus(status: Short) {
when (status) {
200 -> println("All good") // Today, compiler error: "Incompatible types: Int and Short"
else -> println("Error $status")
}
}
This is confusing and inconsistent to me, because this is just fine today:
fun makeShort(s: Short) = s
val x = makeShort(200)
So the compiler already does type inference of some integer literals, but not all, and it’s not customizable.