New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make illegal state unrepresentable construction validation #830
Comments
Are you looking for asserts? |
Unless I am missing something obvious, asserts, including those based on
@Assert annotation, are ignored. This is clearly stated in the docs: "In
production code, assertions are ignored, and the arguments to assert aren’t
evaluated.". Using the *making invalid state unrepresentable*, which comes
out of Type Driven Development (the other TDD), this would need to be true
in production as well. So, using assert is not an option.
…On Fri, Dec 23, 2022 at 5:21 PM Remi Rousselet ***@***.***> wrote:
Are you looking for asserts?
—
Reply to this email directly, view it on GitHub
<#830 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAOVLAXVB22PDYEI7PT4Q3DWOYXXVANCNFSM6AAAAAATIDUHZQ>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Asserts (which indeed aren't enabled in release mode) is generally the way to do that in Dart. There's currently no alternative using Freezed, yes |
First, I wish to thank you for taking the time to answer my question on which is very possibly a holiday weekend for you as it is for me. Also, I want to make sure you understand I really admire this package. I ran into this issue, have made compromises, but hoped there was something I was missing. I am very much a designer/architect thinker, but love to code. Invariants, in my opinion, in OO languages, should be enforced in the object/class, ideally at construction. So, I have a few further questions if you don't mind, though there is no rush. I would like to explore some further options on my own. I do believe that I can do as I desire if I use equatable and serializable. Assuming that is true, is there a specific thing that makes what I wish to do impossible, such as union types or pattern matching? Is it the requirements of a certain package you are using that makes what I wish to do not possible? If what makes this not possible because of code built specifically for the package, would you mind pointing me towards it? I might clone it and look at it myself as time permits, not that I think you have done something wrong. One possible solution that comes to mind, and likely not the best, would be to create an assert. Let's call it InvariantValidator. This would look like the Assert validator - in my mind. It would inject a method that would automatically get called on construction. If the object is mutable, it would also get called when mutated. Any thoughts or suggestions you may have would be most appreciated. Hope you enjoy the weekend! |
It's not impossible to implement something to support this in Freezed. It's just not there It's low priority for me. Especially considering with the upcoming Dart features, Freezed probably won't be useful for long |
Your last statement tells me I need to do a better job keeping up with roadmap docs. Thanks for the feedback! |
I have no plan to work on this, so closing |
Support for this would be very nice. In my mind, the biggest drawback of this package currently.
i.e add |
Is your feature request related to a problem? Please describe.
It seems there is no capability for construction validation, thus I cannot apply use "illegal states unrepresentable" principles.
Describe the solution you'd like
Say I want a TimeEntry class that has a start and end time. The domain invariant is that end time must be after the start. If it is, then the object constructs. If not, then the object does not construct throwing an error, preferably an exception of my choice.
Describe alternatives you've considered
The only alternatives I see is to not use freezed at all.
Additional context
none
The text was updated successfully, but these errors were encountered: