camdenorrb
07/08/2019, 8:26 PMNir
07/08/2019, 8:30 PMcamdenorrb
07/08/2019, 8:34 PMNir
07/08/2019, 8:34 PMcamdenorrb
07/08/2019, 8:34 PMadamd
07/08/2019, 8:36 PMcamdenorrb
07/08/2019, 8:37 PMadamd
07/08/2019, 8:39 PMcamdenorrb
07/08/2019, 8:40 PMNir
07/08/2019, 8:40 PMadamd
07/08/2019, 8:42 PM+=
is confusing?sxtanna
07/08/2019, 8:44 PMadamd
07/08/2019, 8:45 PMsxtanna
07/08/2019, 8:45 PMadamd
07/08/2019, 8:46 PMsxtanna
07/08/2019, 8:46 PMadamd
07/08/2019, 8:47 PMsxtanna
07/08/2019, 8:49 PMadamd
07/08/2019, 8:49 PMsxtanna
07/08/2019, 8:49 PMadamd
07/08/2019, 8:50 PMsxtanna
07/08/2019, 8:51 PMadamd
07/08/2019, 8:51 PMthings
would be a mutable collection, instead of immutable?sxtanna
07/08/2019, 8:52 PMadamd
07/08/2019, 8:52 PMsxtanna
07/08/2019, 8:52 PMNir
07/08/2019, 8:54 PMadamd
07/08/2019, 8:57 PMNir
07/08/2019, 8:57 PMadamd
07/08/2019, 8:57 PMYeah, this shit confused a new programmer to the language
sxtanna
07/08/2019, 8:58 PMadamd
07/08/2019, 8:58 PMnew programmer to the language
, the cost of an adding an element to an array is not the first thing I'm expecting/thinking ofcamdenorrb
07/08/2019, 8:59 PMsxtanna
07/08/2019, 8:59 PMNir
07/08/2019, 8:59 PMadamd
07/08/2019, 9:00 PMNir
07/08/2019, 9:00 PMsxtanna
07/08/2019, 9:00 PMadamd
07/08/2019, 9:01 PMNir
07/08/2019, 9:01 PMconst
a la C++, Rust, Dadamd
07/08/2019, 9:02 PMoperator fun
supporting adding an elementNir
07/08/2019, 9:02 PMcamdenorrb
07/08/2019, 9:03 PMadamd
07/08/2019, 9:03 PMcopy
explicitlyNir
07/08/2019, 9:03 PMx = x + y
is already making copies, and it's pretty explicit about itadamd
07/08/2019, 9:03 PMcamdenorrb
07/08/2019, 9:03 PMadamd
07/08/2019, 9:04 PMNir
07/08/2019, 9:04 PMsxtanna
07/08/2019, 9:05 PM+
is explicit enough to show what its actually doingadamd
07/08/2019, 9:05 PMsxtanna
07/08/2019, 9:05 PMadamd
07/08/2019, 9:05 PMsxtanna
07/08/2019, 9:06 PMNir
07/08/2019, 9:06 PMsxtanna
07/08/2019, 9:06 PMadd
function, it makes sense for them to support the +
operatorcamdenorrb
07/08/2019, 9:06 PMadamd
07/08/2019, 9:06 PMNir
07/08/2019, 9:07 PMadamd
07/08/2019, 9:07 PMNir
07/08/2019, 9:07 PMadamd
07/08/2019, 9:07 PMcamdenorrb
07/08/2019, 9:07 PMsxtanna
07/08/2019, 9:07 PMcamdenorrb
07/08/2019, 9:08 PMadamd
07/08/2019, 9:09 PMcamdenorrb
07/08/2019, 9:09 PMadamd
07/08/2019, 9:10 PMsxtanna
07/08/2019, 9:10 PMadamd
07/08/2019, 9:11 PMcamdenorrb
07/08/2019, 9:13 PMadamd
07/08/2019, 9:14 PMsxtanna
07/08/2019, 9:15 PMadamd
07/08/2019, 9:16 PMsxtanna
07/08/2019, 9:16 PMadamd
07/08/2019, 9:19 PMthis shit
- maybe it was my misunderstanding, but I tried to understand where it came from 🙂sxtanna
07/08/2019, 9:19 PMadamd
07/08/2019, 9:20 PMcamdenorrb
07/08/2019, 9:21 PMadamd
07/08/2019, 9:24 PMNir
07/08/2019, 9:24 PMadamd
07/08/2019, 9:25 PMNir
07/08/2019, 9:25 PMadamd
07/08/2019, 9:25 PMNir
07/08/2019, 9:25 PMconst
adamd
07/08/2019, 9:26 PMNir
07/08/2019, 9:26 PMList
is not an immutable data structure, it's just a read-only view of some data structure, that may or may not be immutableadamd
07/08/2019, 9:27 PMNir
07/08/2019, 9:27 PMMutableList
inheriting from List
, that wasn't invented in Kotlinval x: MutableList<Int> // populate
foo(x) { x += 5 }
adamd
07/08/2019, 9:28 PMNir
07/08/2019, 9:28 PMfoo
takes e.g. List
and a lambdaadamd
07/08/2019, 9:29 PMNir
07/08/2019, 9:30 PMadamd
07/08/2019, 9:30 PMNir
07/08/2019, 9:30 PMadamd
07/08/2019, 9:32 PMNir
07/08/2019, 9:35 PMadamd
07/08/2019, 9:35 PMNir
07/08/2019, 9:35 PMadamd
07/08/2019, 9:37 PMNir
07/08/2019, 9:38 PMcamdenorrb
07/08/2019, 9:42 PMghedeon
07/08/2019, 9:45 PMplus/+
and confusion:
https://youtrack.jetbrains.com/issue/KT-9992plus
and plusElement
🙂Nir
07/08/2019, 9:47 PMcamdenorrb
07/08/2019, 9:49 PMNir
07/08/2019, 9:51 PMcamdenorrb
07/08/2019, 9:52 PMNir
07/08/2019, 9:56 PMvector<Foo>
is completely contiguous in memory.camdenorrb
07/08/2019, 10:02 PMNir
07/08/2019, 10:10 PMVec3
, which was literally 3 doubles, was pointer-indirected (like all Java types other than int, etc)Toddobryan
07/08/2019, 11:01 PMList
, Kotlin uses ArrayList
, which is amortized O(1) to add elements, so it's doing the same thing under the hood, but isn't nearly so awful. tl;dr Use List
instead of Array
if the size will change.Nir
07/08/2019, 11:11 PMMutableList
List
you can't perform any operations that modify the object (unless you downcast first)x += 1
for a List
is just syntactic sugar for x = x.plus(1)
(assuming x
is a var
)Toddobryan
07/09/2019, 3:15 PMList
. This is different than Scala, which uses Cons
lists, so it's O(1) to add at the beginning, but O(n) to add at the end. Because of the way ArrayList
works, the reverse is true in Kotlin.