Mobile

The Road to Name-Based Destructuring

Scala 3’s experimental `-Xname-based-destructuring` flag quietly retools pattern matching, letting developers unpack case classes by field name instead of position—an opt-in syntax shift that could unseat decades of positional destructuring habits and streamline refactoring for data-heavy codebases. The compiler now accepts `val (x, y)` for named fields and `val [x, y]` for positional, with stable release slated for the next minor version.

Kotlin 2.3.20 introduces an experimental feature that changes how destructuring declarations work: instead of relying on the position of properties in a data class, you can now unpack values by their field names. The feature is enabled with the compiler argument -Xname-based-destructuring=only-syntax and is expected to become stable in version 2.5.0 (end of 2026). By version 2.7.0 (end of 2027), the default behavior for destructuring with parentheses will switch from position-based to name-based.

What changes

Currently, destructuring in Kotlin is positional. Writing val (name, age) = person extracts the first and second components of person, regardless of what they are named. This works fine for simple cases but creates problems when you reorder properties, change a computed property into a primary one, or turn a class into an interface. The variable names you choose in the destructuring declaration have no connection to the actual property names.

The new syntax puts val inside the parentheses, one per property:

(val name, val age) = person

The order no longer matters. You can also rename properties on extraction:

(val age, val theName = name) = person

For cases where position-based destructuring still makes sense — pairs, triples, collections — the new syntax uses square brackets:

val [x, y] = point
// or
[val x, val y] = point

This syntax works everywhere destructuring is allowed: lambda expressions, loops, and let blocks.

Migration path

The compiler provides a migration helper under -Xname-based-destructuring=name-mismatch. When enabled, it warns about cases where position-based and name-based destructuring produce different results, or where code will stop compiling once the default changes. The IDE (IntelliJ IDEA) will offer quick-fixes, such as suggesting the new syntax or renaming variables.

You can already test the future default behavior with -Xname-based-destructuring=complete, but JetBrains warns that this can break existing code. The migration period is deliberately long: the feature is experimental in 2.3.20, stable in 2.5.0, and the default changes in 2.7.0. If the ecosystem is not ready by 2027, the change may be postponed.

Tradeoffs

Name-based destructuring solves real problems: it prevents accidental property swaps, simplifies refactoring, and works with interfaces and value classes without requiring manual componentN() functions. However, it introduces a new syntax that developers must learn, and it breaks existing code that relies on positional destructuring with mismatched variable names. The compiler will not deprecate componentN() functions for data classes — they will still be generated — but multi-field value classes will only support name-based destructuring.

When to use it

If you are starting a new project or have a small codebase, you can enable -Xname-based-destructuring=only-syntax now to get familiar with the new syntax. For larger projects, wait until the feature reaches stable status in 2.5.0, then use the migration helper to identify and fix problematic destructuring declarations. The long timeline gives you room to adapt without pressure.

Bottom line

Name-based destructuring is a significant change to Kotlin's syntax that improves safety and maintainability. The migration is well-planned, with tooling support and a multi-year transition period. Start experimenting now to avoid surprises when the default flips.

Similar Articles

More articles like this

Mobile 1 min

Android 17 is getting redesigned emoji, and Google is clearly never bringing back the blobs [Gallery]

Android 17's revamped emoji set marks a definitive shift away from 2D designs, with Google opting for 3D textures across its entire emoji catalog, a move that effectively seals the fate of the beloved blob emoji, which have been absent since Android 11's transition to Unicode Consortium standards.

Mobile 2 min

Introducing Googlebook, designed for Gemini Intelligence - blog.google

Introducing Googlebook, designed for Gemini Intelligence blog.google

Mobile 1 min

Hello Developer: May 2026

Apple’s May 2026 developer roadmap quietly mandates Accessibility Nutrition Labels for all App Store submissions, while accelerating the Intel-to-Apple Silicon transition deadline—effectively sunsetting Rosetta 2 support by year-end. The shift pairs compliance pressure with a push for Infinity Nikki’s open-world engine, signaling a dual bet on accessibility metadata and next-gen game frameworks to lock in ecosystem dominance.

Mobile 1 min

Building for the Intelligence System on Android

Android's seismic shift from operating system to intelligence system is poised to upend app development, as devices increasingly anticipate user needs and automate tasks with Gemini Intelligence, a suite of features that integrates hardware and software to deliver personalized experiences. Task Automation with Gemini enables apps to drive high-intent traffic without code changes, leveraging built-in transparency and control. This integration promises to redefine user engagement on Android.

Mobile 1 min

Get the most out of your Apple Developer account

Unlocking Exclusive Access: A free Apple Developer account, distinct from paid memberships, grants developers direct downloads and support resources, including beta versions of Xcode and Apple operating systems, enabling early testing and feedback on upcoming features and API changes. This separate account allows developers to submit feedback and ensure app compatibility on day one of each new OS release.

Mobile 1 min

WebKit Features for Safari 26.5

Safari 26.5 quietly arms front-end developers with four surgical CSS and DOM upgrades—`:open` pseudo-class for state-aware styling, `element-scoped` randomness to tame entropy, SVG gradient interpolation via `color-interpolation`, and `ToggleEvent.source` to trace popover triggers—while slipping in the Origin API as a potential cross-origin game-changer.