-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Easy HashCode and Equals override #105
Comments
I would expect that allocating new objects to generate a hashcode would be terribly inefficient. |
@nosami, just compiler job, could be done using macros before compilation. Also the [Attribute] suggestion doesn't generate new objects. |
While I love the suggestion and would have said "yes, one thousand times yes" a little while ago I think this may be redundant if C# gets record types. One of the features of records is that they have structural equality by default, which is what you're suggesting here. However, this might still be useful, especially if records types don't make it into the language for whatever reason. |
I also like the idea for record types, kind of the scala "case class", but I think the way I proposed feels more the C# way. Also a feel that adding a record type is just what a struct should be, adding class, structs and record type seems too much for beginners. |
I'm not sure case classes are analogous to record types; they're more the equivalent of discriminated unions, if you're familiar with F#. A C# record type of your example would (under current suggested syntax) look like this:
You get structural equality (along with hashcodes), immutability and ToString for free. |
We prefer to avoid giving language semantics to attributes. The proposed C# records are exact analogs to Scala's case classes, and would appear to address the underlying use cases. |
It appears as if there's very little interest. So, more important things are being appropriately prioritized. |
I wonder what are those more important things. The interest was suppressed with the promise of records being the solution (which they are not) and are already upcoming really soon™. Records have still not arrived. We will have In the meantime just use valuetuples with named members... I believe these cases better show the importance of the community feedback than the nice diagrams posted yearly by MS folks. |
The current set of 8.0 features for example :)
There has been minimal community feedback that this is an issue that warrants a lot of attention from MS. This issue alone only has a 10 posts from a handful of people. |
Those are nice features indeed. Now what stops us from reopening this issue, to let the community provide feedback, now, when we can see that the promise of records solving this use case (which is not completely true anyway) has been a false excuse to close the issue, as a total of 5 language versions were released since the closure of the ticket, none addressing this point. The lack of interest and discussion is not a valid excuse, as many are intimidated by seeing the issue as closed, and may think that the discussion is over, so they won't express their interest as it were still open. I truly hope it is not. |
Proposition
An easy way to implement default HashCode and Equals method, similar to that implemented by anonymous types
Situation
If the HashCode and Equals are already implemented by the language in some situation, why I should reimplement it?
I got myself, doing this more than one time:
Why not something like this:
Or maybe:
The text was updated successfully, but these errors were encountered: