>
> Not true. interface{} and reflection is, for example, used by fmt.Printf
> for purpose where generics won't help. Alternatively everything must have a
> Format() method. But predeclared types cannot have methods.
write a compile time type safe generic *reduce *function with the following
signature which works for all slices of any element type :
func reduce<A,B>(array []A,out B,in A)B {}
you can't do that in Go .
used by fmt.Printf for purpose where generics won't help.
Interfaces won't help either when you're basically using them as C (*void)
.
Le samedi 29 juillet 2017 15:38:29 UTC+2, Jan Mercl a écrit :
>
> On Sat, Jul 29, 2017 at 3:28 PM <[email protected] <javascript:>> wrote:
>
> > What is overrated is the use of "interface { }" and reflection AKA
> runtime magics which has no place in a modern statically typed language.
>
> interface{} is not a replacement of generics. Interfaces with a real
> methods set, like sort.Interface sometimes are.
>
> > It's a cop-out, it's dirty and a direct consequence of the absence
> of generics in Go.
>
> Not true. interface{} and reflection is, for example, used by fmt.Printf
> for purpose where generics won't help. Alternatively everything must have a
> Format() method. But predeclared types cannot have methods.
>
> --
>
> -j
>
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.