https://kotlinlang.org logo
Title
h

Hullaballoonatic

11/10/2018, 7:40 PM
i'm saying it'd be nice if i didn't have to write
toDouble()
all over my mathematics in kotlin šŸ˜‘
k

karelpeeters

11/10/2018, 7:41 PM
Okay but that's for both of my above cases, do you want both to go to doubles?
h

Hullaballoonatic

11/10/2018, 7:41 PM
automatically, yeah
k

karelpeeters

11/10/2018, 7:42 PM
The first one I understand, I agree that it's annoying without any real safety benefits.
h

Hullaballoonatic

11/10/2018, 7:42 PM
also, is double just a float with twice the memory allocated?
k

karelpeeters

11/10/2018, 7:42 PM
But
3 / 2
is just integer arithmetic and we need that too.
h

Hullaballoonatic

11/10/2018, 7:42 PM
i know i learned that at one point, but forgot it, because i learned it before it was of any practical use to me
k

karelpeeters

11/10/2018, 7:42 PM
(Yes, double is float with more bits)
h

Hullaballoonatic

11/10/2018, 7:43 PM
meaning you want
3/2
to round to remain as an int?
k

karelpeeters

11/10/2018, 7:43 PM
Yes, I use that a lot.
h

Hullaballoonatic

11/10/2018, 7:43 PM
ah, good point
i guess i never considered it because in java you have to use ceiling and cast back to int
k

karelpeeters

11/10/2018, 7:44 PM
No, it's the same in Java and every other C-like language there is.
h

Hullaballoonatic

11/10/2018, 7:44 PM
or i think casting back to int does that by itself now that i think about it..
k

karelpeeters

11/10/2018, 7:44 PM
Not even a cast, that's literally what / on its does.
h

Hullaballoonatic

11/10/2018, 7:44 PM
nvm me then... i'm dumb!
k

karelpeeters

11/10/2018, 7:44 PM
That's also what the dedicated CPU instruction does :)
h

Hullaballoonatic

11/10/2018, 7:45 PM
i just like my math equations in my code to be devoid of much other than variables, numbers, and mathematical operators
the casting distracts the eye from the important parts
c

Chris Cunningham

11/10/2018, 7:45 PM
Just write it with the decimal point 3.0 / 2.0
Otherwise it would think you are working with int and not double
h

Hullaballoonatic

11/10/2018, 7:46 PM
maybe the same reason i don't like
!foo.isEmpty
and prefer
foo.isNotEmpty
yeah, you're very correct, Chris
but that doesn't work if your integers are stored as variables
c

Chris Cunningham

11/10/2018, 7:48 PM
Oh so you mean wanting to divide ints with a double result
h

Hullaballoonatic

11/10/2018, 7:48 PM
val foo = 3
val bar = .3
println(foo + bar)
does not compile
c

Chris Cunningham

11/10/2018, 7:48 PM
Yeah need to cast one of them
h

Hullaballoonatic

11/10/2018, 7:48 PM
i've been dissuaded from dividing ints into automatic doubles
c

Chris Cunningham

11/10/2018, 7:48 PM
I still rather cast, type conversion should be explict
h

Hullaballoonatic

11/10/2018, 7:49 PM
maybe i just like java's casting more than kotlin's?
c

Chris Cunningham

11/10/2018, 7:49 PM
Talking as vs a cstyle cast
h

Hullaballoonatic

11/10/2018, 7:49 PM
(int)
is a lot less verbose than
toInt()
or
as Int
but i get it
there's no perfect solution here, and i appreciate hearing the counter-arguments
c

Chris Cunningham

11/10/2018, 8:54 PM
Yeah I am pretty used to the c style ones
Not sure about kotlin but in C#
(T)
has a different meaning then
as T
as well
k

karelpeeters

11/10/2018, 10:22 PM
Btw if you're really frustrated about this you can define/generate code like
inline operator fun Double.plus(other: Int) = this + other.toDouble()
and friends.
h

Hullaballoonatic

11/10/2018, 10:22 PM
okay, thanks, Karel! you're so helpful
c

Chris Cunningham

11/10/2018, 10:37 PM
just be sure that is known and does not confuse the crap out of the rest of the devs on the project