Hi. There are parts that make me wonder why it is ...
# getting-started
d
Hi. There are parts that make me wonder why it is not supported in Kotlin. I first defined the variable using the Destructuring Declaration. And if I try to destruct and substitute it again, an error will occur. Is there a way to reuse variables with destructuring ?
Copy code
var (a, b) = somePair() // OK
(a, b) = somePair() // Error !
d
There isn't a way, plus reusing variables isn't a good idea in the first place.
d
@Daniel Pitts I wonder why it's not a good idea.
c
It's not a good idea because it means values change. If you take a look at the function, you cannot know in one single look what the value of
a
will be, because it could be changed anywhere in the function. I know this seems like a very small detail at first, but trust us, immutability makes everything a lot simpler. It allows writing much more complex systems while keeping individual functions simple.
plus1 3