I mean, if your IDE does it for you, is it really that much better that it's shorter?
not the IDE, its the compiler. this is also not some AI shit, in many cases (not all) the compiler can actually figure out how to do this, because it's not hard, it would just be a lot of boilerplate if written manually.
Why did you even bring up AI? IDEs have been able to generate equality functions for decades without AI.
It's kinda neat to have this defined directly in the language so that compilers can implement it, but creating equality function is so low effort that this doesn't really seem like a big deal.
Like, you define the members in a class, then you tell your IDE to generate getters, constructor, equals, hashcode, etc all in like 5 seconds.
I like it, it's nice when the language itself defines reasonable defaults for things, but realistically you're saving yourself a few seconds of effort.
Yeah but if the class changes you need to update everything, you got all that boilerplate taking up space for no real reason, etc...
The Rust way's just a lot cleaner imo.
It's like 5 seconds to regenerate it. Boilerplate doesn't matter, just collapse it. The only real issue is remembering to update it, if you make a change.
Like I said, I prefer for rust does it, it's just not a big deal
Isn't it obvious? More code to skim, scroll over and maintain if something changes. If you add a struct field, your manual EQ implementation still compiles and seems to work but is wrong and will lead to bugs. Yes, solving this for 99,999% of cases with an attribute is just far superior and does make a difference (while keeping it easy to manually implement it if needed). Hash and Ord and some other traits can be implemented in a similar fashion btw..
I said it was better, just not much better.
The maintenance costs of equals is nearly zero. Scrolling over boilerplate seems like a real stretch, like saying a novel with a picture every chapter is harder to read.
I like that you can't accidentally forget to update it, which is kinda nice but is rarely a concern.
And it's a bit more readable, which is nice.
It's better, but folks are talking like it's Super Jesus and I think it's more like finding a dollar in the parking lot.
I've only had to implement equality in C# but that didn't seem that hard of a problem. you just expand the operator = function
Then you should also override Equals(object)
, GetHashCode
, and implement IEquatable<T>
.
Thankfully a lot of the usual boilerplate code can be avoided using a record
class or struct:
public record Person(string Name, uint Age);
Oh well, It does show how little I do have to actually use that. It just hasn't come up that much
Programmer Humor
Post funny things about programming here! (Or just rant about your favourite programming language.)
Rules:
- Posts must be relevant to programming, programmers, or computer science.
- No NSFW content.
- Jokes must be in good taste. No hate speech, bigotry, etc.