TLDR; I got confused from the documentation. Moving the Person example away from the top to emphasize Kotlin de-structuring is meant for Pair/Entry type situations could be a big help.
I also find the documentation here misleading, and landed on this page after confusion there. The top example is definitely misleading without showing the Person constructor.
The position-based destructuring’s primary use-case is to work with mostly structural types like
Pair
andTriple
,
If this is the case, the documentation should begin with such an example. Also perhaps the documentation should explicitly mention de-structuring is positional. I only inferred this after reading the component1() component2() convention details.
To the point of symmetry with data class constructors. While mostly true, they aren’t quite symmetric to me; if a data class is refactored to add a first parameter, compilation of constructor parameters will break. But the now-invalid de-structuring will compile silently and still “work”, causing a particularly nasty type of error. This feels more unsafe. Additionally, it’s easier to look up construction sites during refactor (and more straightforward) than de-structure sites. It’s also more common to explicitly mark types in constructors than in de-structures, so there may be less type safety.
Considering that, maybe the documentation should even suggest the with(…)(…) syntax mentioned here for de-structuring Data classes with many, potentially changing fields like server response objects. Leave de-structuring to Tuples where positional thinking is implicit.