https://kotlinlang.org logo
#codereview
Title
# codereview
t

tenprint

03/16/2019, 2:42 PM
This is probably not ideal… open to any feedback
Copy code
sharedElements?.let { thisSharedElements -> 
  names?.let { thisNames ->
    viewHolder?.let { thisViewHolder ->
      thisSharedElements[thisNames[0]] = thisViewHolder.itemView
    }
  }
}
p

Pavlo Liapota

03/16/2019, 5:06 PM
Why not just this?
Copy code
if (sharedElements != null
		&& names != null
		&& viewHolder != null) {
    sharedElements[names[0]] = viewHolder.itemView
}
If you do this often, then I would recommend to add extension function to your
sharedElements
to hide this code and call it like this:
Copy code
sharedElements?.setElement(names, viewHolder)
It depends on details of your real usages.
t

tenprint

03/16/2019, 5:27 PM
Thanks
Why not just this?
These are “platform” types in Android, so they are not
val
. I can do that, but would need to assign them all to `val`s first
so using the nested
?.let {...}
would be fewer lines of code
but ugly 🙂
p

Pavlo Liapota

03/16/2019, 5:36 PM
I see… but it is more important for code to be readable than short 🙂
t

tenprint

03/16/2019, 5:39 PM
good point 👍
thanks for your feedback!
u

ursus

03/23/2019, 3:44 PM
yea dont do that
8 Views