News for hackers. Stuff that matters.
Re:Maybe adding generics to Go is about syntax after all by dagss on Tuesday September 04, 2018 @11:01AM (#17909505)
...except that both can be applied to solve the same problems.

And so they are in fact very related.

For instance with a macro you could do (made up syntax)

SortIntSlice = mymacros.MakeSorter!(int)

...then at compile time have code for sorting a slice of ints generated.

This is again similar to C++ templates (main difference is C++ will implicitly instantiate instead of explicitly).

And C++ doesn't need generocs because people use templates instead.

They really are in the same problem domain.

Re:Maybe adding generics to Go is about syntax after all by djur on Tuesday September 04, 2018 @11:18AM (#17909611)
Using macros to implement generics has the same problem that C++ templates have, which is described in the Go 2 generics proposal: it's difficult to provide clear error messages for developers in many cases. Functions parameterized on a single type are the easy problem to solve. Where things get thorny is when you parameterize on multiple types with various constraints and/or have some kind of interaction in the function body. The goal of the Go 2 generics contracts (and C++ concepts, Haskell typeclasses, Rust traits, etc.) is to make those expectations explicit.
Re:Maybe adding generics to Go is about syntax after all by slavapestov on Tuesday September 04, 2018 @06:24PM (#17913384)
Macros and C++ templates are also incompatible with separate compilation which leads to increased compile times and binary bloat.