Skip to content

Structs and extension structs as a solution for data classes and wrapper-less views #2360

Closed
@leafpetersen

Description

@leafpetersen

This is a meta-issue to collect up discussion around a proposal I've landed here. This issue is intended to capture broad discussion about the approach. Specific points of discussion around the proposal should be filed as separate discussion issues: I will link the major discussion points in here as appropriate.

Summary

The core of this proposal is to explore an approach to supporting data classes and wrapper-less views while hewing as closely as possible to the syntax and semantics of existing Dart constructs. A secondary goal is to support object representations that are more amenable to compiler optimization, having predictable space layout, loosely specified identity, and limited polymorphism.

The approach here has the user-facing goal that for a consumer of APIs, the basic affordances of a declaration should be obvious to anyone familiar with classes (i.e. what assignments are allowed, and what methods are available). Quoting from the introduction of the proposal:

We aim to minimize the differences between structs and classes. As much as
possible, structs should behave as restrictions of classes, and extension
structs should behave as further restrictions of structs. We specifically aim
to avoid as much as possible having different behaviors for the same concept
(e.g. differences in scoping).

We also aim to minimize the amount of new syntax required, and to maximize the
amount of new functionality that we can provide relative to the syntactic real
estate consumed, and the new cognitive load imposed on users.

Note that while this proposal covers two separate feature sets, they are not necessarily tied together. We could choose to ship one without ever shipping the other, or we could choose to split them into unrelated features. Even if we ship both as designed here, we could (and likely would) choose to ship the pieces separately given existing timelines and plans.

Discussion issues

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions