You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Make hashCode functions better hashes and less boilerplate #88
I looked into this a bit. I agree that we shouldn't be writing our own hashCode functions by hand.
I'm not convinced quiver is really the way to go, though. We should do some performance tests to see how it goes. I guess if the VM inlines the relevant functions heavily it's probably ok, but at first blush the functions involve a lot of nested calls and it's not obvious that the performance would be good.
What we might want to do instead is build some efficient hashCode functions into dart:ui and use those uniformly everywhere.
changed the title [-]Sky Framework should use quiver.core for hashCodes[/-][+]Make hashCode functions better hashes and less boilerplate[/+]on Dec 9, 2015
The semantics would be that it aggregates the hashCodes of each argument in numeric order up to the first one that's equal to hashEnd (and all the others would be asserted to be unspecified, and asserted to be null), and then aggregates the values in the list, if any (some of our hashCode functions have an N+M form where there's a fixed N values and a variable M values in a list). arg1 and arg2 would be required. The function would require that one of the arguments was hashEnd, so if we have 20 arguments, that's up to N=19 values. The hashEnd sentinel value is needed rather than using null for this purpose because sometimes the values we're hashing are null.
(The issue of which hash function to use to aggregate the hashCodes from all the values is a separate issue that I'm not trying to address here, but this would make it trivial to test the entire system with various alternatives if we care enough to go study that later.)
Why not have aggregateHash take optional parameters (rather than named parameters) and then do the Iterable<Object> in another function call? The code that has the N+M structure would then make two calls, which would hopefully be uncommon.
Oh, excellent idea. Especially if we make the list call check for null and handle that specially, so the callers can just pass null lists in without trouble. So something like:
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.
Activity
FlutterIssues commentedon Nov 9, 2015
Thursday Jul 16, 2015 at 22:45 GMT
From @sethladd on June 12, 2015 4:19
Cc @cbracken fyi
On Fri, Jun 12, 2015 at 03:28 Eric Seidel [email protected] wrote:
FlutterIssues commentedon Nov 9, 2015
Thursday Jul 16, 2015 at 22:45 GMT
From @johnmccutchan on June 12, 2015 14:16
https://codereview.chromium.org/1184753002/
Blocked on getting a mirror of quiver setup, which I pinged Robert about.
FlutterIssues commentedon Nov 9, 2015
Friday Aug 14, 2015 at 20:29 GMT
We should no longer be blocked on mirrors. We just use pub get to get all our packages which happen w/o mirroring, no? @abarth
FlutterIssues commentedon Nov 9, 2015
Friday Aug 14, 2015 at 21:44 GMT
Correct.
Hixie commentedon Dec 8, 2015
I looked into this a bit. I agree that we shouldn't be writing our own hashCode functions by hand.
I'm not convinced quiver is really the way to go, though. We should do some performance tests to see how it goes. I guess if the VM inlines the relevant functions heavily it's probably ok, but at first blush the functions involve a lot of nested calls and it's not obvious that the performance would be good.
What we might want to do instead is build some efficient hashCode functions into dart:ui and use those uniformly everywhere.
Hixie commentedon Dec 8, 2015
(We should totally use quiver's "areEqualityGroups" to test all our hashCode/operator== functions, though: https://www.dartdocs.org/documentation/quiver/0.21.4/quiver.testing.equality/areEqualityGroups.html )
a14n commentedon Dec 8, 2015
Alternatively/additionnaly you can use source_gen to generate a class/mixin that contains
hashCodeandoperator ==.I use something similar in zengen.
sethladd commentedon Dec 8, 2015
Any resolution here? Or shall we close this one?
abarth commentedon Dec 9, 2015
I'm not sure it's worth adding a code generation step. That introduces complexity in the rest of our workflow.
We can close the issue if you want. I think it might be better to rename the issue to something like "overriding operator== has too much boilerplate".
Hixie commentedon Dec 9, 2015
well we definitely need a better way to do hashcodes even if it's not with quiver.
[-]Sky Framework should use quiver.core for hashCodes[/-][+]Make hashCode functions better hashes and less boilerplate[/+]Hixie commentedon Dec 9, 2015
@abarth How would you feel about a function with the following signature in
dart:ui?The semantics would be that it aggregates the hashCodes of each argument in numeric order up to the first one that's equal to hashEnd (and all the others would be asserted to be unspecified, and asserted to be null), and then aggregates the values in the list, if any (some of our hashCode functions have an N+M form where there's a fixed N values and a variable M values in a list). arg1 and arg2 would be required. The function would require that one of the arguments was hashEnd, so if we have 20 arguments, that's up to N=19 values. The hashEnd sentinel value is needed rather than using null for this purpose because sometimes the values we're hashing are null.
(The issue of which hash function to use to aggregate the hashCodes from all the values is a separate issue that I'm not trying to address here, but this would make it trivial to test the entire system with various alternatives if we care enough to go study that later.)
abarth commentedon Dec 9, 2015
Why not have
aggregateHashtake optional parameters (rather than named parameters) and then do theIterable<Object>in another function call? The code that has the N+M structure would then make two calls, which would hopefully be uncommon.Hixie commentedon Dec 9, 2015
Oh, excellent idea. Especially if we make the list call check for null and handle that specially, so the callers can just pass null lists in without trouble. So something like:
You'd use it as (this is for LinearGradient):
(Today that function body is 16 lines long.)
abarth commentedon Dec 9, 2015
Yeah.
a14n commentedon Dec 9, 2015
Another pattern is to use an
_undefinedconst as default parameter. It will allow to avoid the use ofhashEndeverywhere.Hixie commentedon Dec 9, 2015
Oh, yeah, making the sentinel be the default value of these arguments is a much better solution.
eseidelGoogle commentedon Dec 10, 2015
Thank you very much!
github-actions commentedon Sep 6, 2021
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.