https://kotlinlang.org logo
#getting-started
Title
# getting-started
s

Slackbot

05/04/2021, 6:54 PM
This message was deleted.
c

Casey Brooks

05/04/2021, 7:07 PM
val (hello, world) = "hello" to "world"
. The
to
function makes a
Pair
, which can be destructured
c

CLOVIS

05/04/2021, 8:09 PM
This is probably a bad idea for performance, at least until pair gets rewritten as a
value class
(if it ever does)
n

nanodeath

05/04/2021, 8:10 PM
performance impact is likely to be very minimal, especially if the JVM decides to allocate the Pair on the stack
c

Casey Brooks

05/04/2021, 8:18 PM
Unless you’re building something that is very performance-sensitive (database engine, HTTP client, UI toolkit, low-level stuff like that, or data processing on very large inputs), it’s usually better to optimize code for readability rather than doing a bunch of “micro-optimizations”. In typical application code, you’ll spend more time fixing bugs in logic than you will trying to make it run faster, so it’s better to set yourself up for readability and maintainability instead of using uglier code that is more performant
☝️ 1
s

Sumeet Parmar

05/04/2021, 8:21 PM
agree with @Casey Brooks — write for clarity than syntax cleverness
n

nanodeath

05/04/2021, 8:29 PM
a lot of questions I see on Getting Started is about contorting Kotlin into doing things in as few lines of code as possible, which isn't actually what Kotlin is about. in this case you're probably better off with two assignments, unless the thing on the right-hand side is already a single data class or something
s

Sumeet Parmar

05/04/2021, 8:32 PM
I’m seeing lot of issues within mature codebases- ppl electing to be fancy and ensuing havoc
n

nanodeath

05/04/2021, 8:33 PM
or maybe "how do I do this Ruby/Python pattern in Kotlin" :)
💯 2
2 Views