2

So, reading golang blog on slices there is a snippet by Rob Pike

A weakness of Go is that any generic-type operations must be provided by the run-time.

which I don't quite understand.

Can one rephrase same sentence?

Considering the context before and after this sentence I assume we can not program generic-type methods (consuming, let's say, slices of byte/int/float etc), but rather should use built-ins.

So, the quirkiest part for me is provided by the run-time, - is that equals to provided by the language?

4

So, the quirkiest part for me is "provided by the run-time," - is that equals to "provided by the language"?

Yes. What it means is that Go has a handful of built-in generic types, such as arrays/slices, channels, and maps, that can have any type put into them, but that's all you get; there's no support for defining your own custom generic types.

  • However, one could use the interface{} (empty interface) type as the most general type. – Basile Starynkevitch Apr 26 '17 at 4:29
  • 2
    @BasileStarynkevitch That's not a generic type, that's a Top type (supertype of all other types). "Generic types" usually means "parametric polymorphism", which is far more useful. – Jack Apr 26 '17 at 7:01
  • Yes, but I did not wrote: "generic type", so I knew that. – Basile Starynkevitch Apr 26 '17 at 7:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.