Quick style question. Say you're given `a: List&lt...
# announcements
r
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
3️⃣
a.map(::B)
k
Hard 2️⃣, 1️⃣ strongly suggests it does depend.
Well 4️⃣
List(a.size, ::B)
😏
👍 4
n
How about a list of pairs?
r
@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
Oh, you’re right.
d
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
Hmm I would have thought it would still be allowed but thinking a bit that would make method resolution confusing.
👍 1
r
Okay, I was leaning that way too, but It's hard to shake the appeal of shorter lines. Thanks everyone!
a
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