Add data classes
Immutable data are used heavily for web applications today, commonly with Elm-like (redux, ngrx, ...) architectures. Most common thing web developer is doing with data is creating a copy of it with some fields changed, usually propagated to the root of state tree. JavaScript has spread operator for this. There should be a easy way to use immutable data structures in Dart. I would like to have data classes (inspired by [Kotlin]( https://kotlinlang.org/docs/reference/data-classes.html)) in Dart. Possible API: ``` data class User { String name; int age; } ``` Compiler assumes that all fields of data class are immutable. Compiler adds `equals` implementation based on shallow equals, `hashCode` implementation based on mix of all object fields, `toString` implementation of the form `<Type> <fieldN>=<valueN>`, and `copy` function to recreate object with some fields changed. You may argue that there is already [Built value](https://github.com/google/built_value.dart) package that allows to do similar things, but we have many issues with package, mainly: 1. It requires writing a lot of boilerplate code 2. It requires running watcher/manual code generation during development. 3. It requires saving generated files to repository because code generation time is too large for big applications. I have found that using built value actually decreases my productivity and I do my work faster with even manually writing builders for classes. If data classes would be implemented on language
Posted by ranquild on Oct 31, 2017, 11:42 AM
Tags
Related issues
- [Meta] Feedback on granular control over Copilot changes
- unexpected status 401 Unauthorized issue
- [MODEL] Measurable quality regression in Claude generation 5 (Fable 5 / Opus 5 / Sonnet 5): worse nonsense detection, ~2x verbosity, under-disclosed model fallb
- [CRITICAL] Subagent spawning and subagent pattern bugs trigger infinite recursion, infinite token usage, grossly inefficient token usage, and lost accumulated s
- Video stops playing after some minutes
- [MODEL] Claude verbose code comments by default — ignores instructions to stop.
Raise real-world problems, find people facing the same issue, and discuss solutions.4,500 issues0 comments
github (Software)
[Meta] Feedback on granular control over Copilot changes
unexpected status 401 Unauthorized issue
[MODEL] Measurable quality regression in Claude generation 5 (Fable 5 / Opus 5 / Sonnet 5): worse nonsense detection, ~2x verbosity, under-disclosed model fallb
[CRITICAL] Subagent spawning and subagent pattern bugs trigger infinite recursion, infinite token usage, grossly inefficient token usage, and lost accumulated s
Video stops playing after some minutes
[MODEL] Claude verbose code comments by default — ignores instructions to stop.
Scope Codex VS Code chats to the current workspace/project
Update on "Co-authored-by: Copilot" in commit messages
Add data classes
Immutable data are used heavily for web applications today, commonly with Elm-like (redux, ngrx, ...) architectures. Most common thing web developer is doing with data is creating a copy of it with some fields changed, usually propagated to the root of state tree. JavaScript has spread operator for this. There should be a easy way to use immutable data structures in Dart. I would like to have data classes (inspired by [Kotlin]( https://kotlinlang.org/docs/reference/data-classes.html)) in Dart. Possible API: ``` data class User { String name; int age; } ``` Compiler assumes that all fields of data class are immutable. Compiler adds `equals` implementation based on shallow equals, `hashCode` implementation based on mix of all object fields, `toString` implementation of the form `<Type> <fieldN>=<valueN>`, and `copy` function to recreate object with some fields changed. You may argue that there is already [Built value](https://github.com/google/built_value.dart) package that allows to do similar things, but we have many issues with package, mainly: 1. It requires writing a lot of boilerplate code 2. It requires running watcher/manual code generation during development. 3. It requires saving generated files to repository because code generation time is too large for big applications. I have found that using built value actually decreases my productivity and I do my work faster with even manually writing builders for classes. If data classes would be implemented on language
Comments (0)
No comments yet. Start the discussion.