that'd be slightly better (but still terrible IMO)...
# getting-started
k
that'd be slightly better (but still terrible IMO) as
Copy code
val (one, two, three) = IntArray(3) { 0 }
a
As I said to the other thread, Your scientists were so preoccupied with whether or not they could, they didn't stop to ask if they should.
k
Agreed, if I had to do this, I'd do:
Copy code
val one = 0
val two = 0
val three = 0
maybe pull up
0
into a top-level constant
a
Yeah, I would just pull it out. I can see why it's less concise than the java way, but I would argue that this is negligible to a certain amount. If you truly have a large number of variables that are starting out at the same value, then an array may not be the worst idea. It just looks awful for 3 items. But imagine 10, or 20.
k
Yup, totally agree. I don't think I've ever even used the Java construct for assigning to multiple variables simultaneously
would rather just be explicit, honestly. Conciseness is less important than readability IMO
☝️ 1
a
100%. I know some developers who love to write
for (...) if (...) return true
in one line, but I never did. Until I came to Kotlin, but that's only because I have
.any { }
hahaha.