top | item 29585230

(no title)

horsemans | 4 years ago

Would you use generics to write the same implementation of min/max for integers and floats?

discuss

order

danachow|4 years ago

Why not? You later seem to think that this would require reflection - but that makes it apparent you don't understand how generics work in a language. They're used at compile time - to avoid runtime checking.

grey-area|4 years ago

You certainly might use them to write a facade which made life easier for consumers of the math pkg and accept floats,ints or uints even if behind the scenes it splits into different implementations.

horsemans|4 years ago

I would not be very happy if every time I called math.Min, I was also, under the hood, calling reflect.TypeOf.

qaq|4 years ago

The fact that you would not need a separate one for each of the: uint8 , uint16 , uint32 , uint64 , int8 , int16 , int32, int64 is not enough ?