The Road to Name-Based Destructuring | The Kotlin Blog
Blog post from JetBrains
Kotlin is undergoing a significant evolution in its approach to destructuring, shifting from a position-based to a name-based system. This change introduces new syntax options, such as using "val" inside parentheses for name-based destructuring and square brackets for positional destructuring, which are currently experimental and can be enabled with specific compiler arguments. The transition aims to address issues related to refactoring, abstraction, and inadvertent errors due to property order mix-ups, by ensuring that properties are accessed by their stable names rather than their order. The compiler provides migration tools and warnings to aid developers in adapting their code, and while name-based destructuring is set to become the default in future Kotlin versions, the plan includes a gradual rollout with substantial time for the community to adjust. This approach maintains backward compatibility with existing data classes while preparing for advanced features like multi-field value classes that will only support name-based destructuring.