by vanessa98 · 11y ago · 0 comments
Edit: On reflection, "traits" is probably the wrong word. C++ has a word for this, but I'm drawing a blank at the moment.
It's the same end result, but without the speed and the type checking of proper Generics.
(Assuming you mean "empty interfaces" (interface{}). Else, regular interfaces are not the same thing as Generics.
>On reflection, "traits" is probably the wrong word. C++ has a word for this, but I'm drawing a blank at the moment.
Templates?
Now, in Go, you don't have generics. But you can have a sort function that takes a type (interface) that means "something that has a less-than function", and because of the way Go does OO, anything that has that function works.
This doesn't get Go to the point of having templates that will take any type whatsoever (unless you use empty interfaces).
I feel like I'm still using the wrong word in one or two places. But I hope this is more clear than my previous comment.
Yeah, that would be Concepts. IIRC, C++ doesn't have them landed yet.
>Now, in Go, you don't have generics. But you can have a sort function that takes a type (interface) that means "something that has a less-than function", and because of the way Go does OO, anything that has that function works.
Yeah, you can have that. But the benefit of generics is that the "things that fit that function" are auto-generated.