Skip to content

Instantly share code, notes, and snippets.

@VovaStelmashchuk
Created May 11, 2025 10:21
Show Gist options
  • Save VovaStelmashchuk/8e012f02a8b650c7e9e17d876c000b28 to your computer and use it in GitHub Desktop.
Save VovaStelmashchuk/8e012f02a8b650c7e9e17d876c000b28 to your computer and use it in GitHub Desktop.
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.
// Try to figure out, what changed, without knowing the details
fun makeConnection(first: User, second: User) {
first.apply {
second.apply {
b = a
c = b
}
}
}
fun makeConnection(first: User, second: User) {
first.b = this.a
second.c = first.b
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment