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

Rahul Singhal

07/08/2022, 5:46 AM
Can we use nested scope function, apply, run, with, let, also. Is it a good practice. If yes, how many nested scope would u prefer?
👍 1
d

David Rawson

07/08/2022, 5:50 AM
There’s some guidance in the official documentation about this: https://kotlinlang.org/docs/scope-functions.html#function-selection
Although the scope functions are a way of making the code more concise, avoid overusing them: it can decrease your code readability and lead to errors. Avoid nesting scope functions and be careful when chaining them: it’s easy to get confused about the current context object and the value of
this
or
it
.
👍 1
👍🏻 1
k

K Merle

07/08/2022, 1:43 PM
In my experience, it tends to decrease the readability of a code.
Usually I'll use just one, and if I need more I might actually add to readability with a variable names. e.g.
Copy code
val something = x?.let{}
val somethingElse = something.apply{}
...
r

Rahul Singhal

07/08/2022, 4:09 PM
Cool😀
49 Views