https://kotlinlang.org logo
#announcements
Title
# announcements
r

Ruckus

07/10/2019, 2:28 PM
Quick style question. Say you're given
a: List<A>
and want an equal amount of `B`s (that don't depend on
A
. Do you prefer: 1️⃣
a.map{ B() }
2️⃣
List(a.size) { B() }
2️⃣ 10
p

pardom

07/10/2019, 2:29 PM
3️⃣
a.map(::B)
k

karelpeeters

07/10/2019, 2:29 PM
Hard 2️⃣, 1️⃣ strongly suggests it does depend.
Well 4️⃣
List(a.size, ::B)
😏
👍 4
n

Nir

07/10/2019, 2:31 PM
How about a list of pairs?
r

Ruckus

07/10/2019, 2:31 PM
@pardom That would only work if
B
takes an
A
as a parameter, but I specifically mentioned
B
does not depend on
A
@karelpeeters
B
Also does not take an
Int
🙂
p

pardom

07/10/2019, 2:31 PM
Oh, you’re right.
d

dalexander

07/10/2019, 2:32 PM
Yeah, that changes my mind, for some reason I thought there was a relationship between the As and Bs on first reading. Shouldn't use
map
if there's no relationship.
👍 1
k

karelpeeters

07/10/2019, 2:32 PM
Hmm I would have thought it would still be allowed but thinking a bit that would make method resolution confusing.
👍 1
r

Ruckus

07/10/2019, 2:33 PM
Okay, I was leaning that way too, but It's hard to shake the appeal of shorter lines. Thanks everyone!
a

Al Warren

07/10/2019, 5:15 PM
What appeals to me is readability. If shorter lines breaks that, I go with the longer version. It's important to be able to reason about the code. I'm very visual, so being able to see what's happening when I scroll through the code is more important than brevity. Either way, I choose based on that.
👍 1
2 Views