dart-lang / language

Design of the Dart language
Other
2.66k stars 205 forks source link

`final` local variables and static immutability are related via closures #160

Open yjbanov opened 5 years ago

yjbanov commented 5 years ago

I'm not sure what's the best place to record this is, so just opening an issue to point it out.

tl;dr final local variables and static immutability are related concerns via closures

The static immutability proposal introduces objects that are deeply immutable and can be shared across isolates. Top-level and static function tear-offs should be shareable too as they have no internal shared mutable state. In fact, you can already spawn an isolate from a top-level function reference today. The static immutability provides an opportunity to expand this capability by allowing closures to be passed to other isolates along with immutable objects, perhaps as fields of those objects. In fact, a lot of Flutter widgets take closures as arguments, such as onTap. However, such closures must only close over deeply immutable final local variables.

It would make the developer experience of using shared closures more pleasant if the ergonomics of final variable was better. This is discussed in https://github.com/dart-lang/language/issues/136.

yjbanov commented 5 years ago

Here's how Skip does this: