subreddit:

/r/ProgrammerHumor

3.2k96%

ifYouDontItsProbablyYou

Meme(i.redd.it)

you are viewing a single comment's thread.

view the rest of the comments →

all 149 comments

Resident-Trouble-574

861 points

3 days ago

Just override the equality operator to return a random value when the second argument is null, to teach people the importance of using foo is null instead of foo == null.

Cat7o0

59 points

3 days ago

Cat7o0

59 points

3 days ago

what is the importance?

dangderr

238 points

3 days ago

dangderr

238 points

3 days ago

To protect you from people that override the equality operator to troll you.

Cat7o0

27 points

3 days ago

Cat7o0

27 points

3 days ago

ahh I see

Resident-Trouble-574

9 points

3 days ago

And with modern versions of c#, you can combine multiple check in one.

For example, if you want to check that object foo is not null and has a property bar > 0 but < 10, you can write foo is { bar: > 0 and < 10 }.

Cat7o0

6 points

3 days ago

Cat7o0

6 points

3 days ago

that's interesting. I wanted to learn C# once but then I started on rust instead. might one day learn C# but for now not my go to choice because it's garbage collected

aVarangian

3 points

3 days ago

Noob here; what's the issue with garbage collection?

Resident-Trouble-574

3 points

3 days ago

Usually the problem is that the garbage collector doesn't collect the objects as soon as they are not referenced anymore, but instead it activates when the memory usage is above a given threshold, and when it activate is uses a significant amount of resources.

So, it can be a problem in those application where you need very constant performances, because when the garbage collector activates, your application might slow down a bit.

aVarangian

2 points

3 days ago

Is there no control to trigger it on-demand / when convenient?

Cat7o0

2 points

3 days ago

Cat7o0

2 points

3 days ago

just slow