this post was submitted on 15 Nov 2024
282 points (93.3% liked)

Programmer Humor

32479 readers
224 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS
 
(page 2) 21 comments
sorted by: hot top controversial new old
[–] Gonzako@lemmy.world 4 points 2 days ago (6 children)

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

[–] copygirl@lemmy.blahaj.zone 7 points 2 days ago (1 children)

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);
[–] Gonzako@lemmy.world 1 points 1 day ago

Oh well, It does show how little I do have to actually use that. It just hasn't come up that much

load more comments (5 replies)
[–] PeriodicallyPedantic@lemmy.ca 2 points 1 day ago (1 children)

I mean, if your IDE does it for you, is it really that much better that it's shorter?

[–] ReversalHatchery@beehaw.org -1 points 1 day ago (1 children)

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.

[–] PeriodicallyPedantic@lemmy.ca 2 points 1 day ago (6 children)

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.

load more comments (6 replies)
load more comments
view more: ‹ prev next ›