memesearch
Generics at Home Go Code

Generics at Home Go Code

Download Find similar pictures
Text on the meme
Me: can we get generics? Pops: no, we have generics at home generics at home: type Comparer interface { Compare(i interface{}) int } // This function panics if i is not a Dog. func (d Dog) Compare(i interface{}) int { if dog, ok := i.(Dog); ok { return d.Weight-dog.Weight } else { panic(fmt.Errorf( "i is not a dog (%s=%#v)", "i", i, )) } }
What it means

A programming meme contrasts a request for generics with a homemade substitute in Go. The code defines a Comparer interface that only works with Dog values and panics when given anything else, mocking an awkward workaround that technically resembles generics but is not truly generic.

Objects
Tags
Source
Type
image
Size
514×487 · 40.9 KiB
Mood
sarcastic
Language
en
Added