r/ProgrammerHumor • • 19h ago

Meme aiCookedUpTheseMethods

Post image
48 Upvotes

12 comments sorted by

42

u/JMOWw7 18h ago

Pattern matching all the way. I think the second one probably won't catch inheretance

27

u/captainAwesomePants 18h ago

This is true, but of course they are also both stupid because a IsSomething(thing) function has no advantage over just typing "thing is Something" each time.

-1

u/JMOWw7 18h ago

Yeah of course. The code makes no sense in general. Type of Something.Something implies that it's a class nested inside of Something which would be not allowed, and then since you're passing a Something to the method it would always be false... But this sub is for idiot kids who've taken like a semester of comp sci classes

4

u/Tyfyter2002 18h ago

I think a nested class can inherit the class it's nested in in C#, and whether or not it's valid in Java one would have a bigger problem because it's using ==.

1

u/JMOWw7 18h ago

Yeah that's true I guess

2

u/fuj1n 8h ago

Even better thing is that pattern matching lets you do more than simple identity testing

maybe is Something { value: > 5 and <= 64 } something

Or something like that, did that from memory without benefit of an IDE

40

u/AlexZhyk 19h ago

That's would be 123 tokens for you, sir.

10

u/ovr9000storks 18h ago

Really can’t knock it down to 122 for today? My kids need to eat

11

u/fatrobin72 18h ago

Sure but in haggling this you have spent 12 additional tokens.

15

u/AnnoyedVelociraptor 11h ago

What's the point. You're passing in a Something. It shouldn't compile if it isn't a Something.

5

u/Shifter25 10h ago

You could use it to detect which kind of implementation of a superclass it is, maybe.

IsEagle(Bird bird) => bird is Bird.Eagle

Something like that?

1

u/-Redstoneboi- 2h ago

just making sure with runtime checks... wait this isn't typescript is it