I complained myself too about not being able to write a generic Min, Max, but I am not so sure anymore myself of the strength of this argument.
The point is: besides Min and Max, what other really good, general, examples are there of really missing? To give an example myself, I'd love to write func (type T) SliceContains(list []T) bool Turns out, it was 99% always strings in my case! Maybe 100%. So I really didn't need it. I *thought* I needed it, but I just wanted to be fancy and write it for all types. Besides like you also said most of these functions are really really trivial to write quickly. I have MaxInt in several packages. What we do undoubtedly need generics for is better type safety in generic data structures and (channel algorithms maybe). Generic (math) algorithms are very powerful too, I personally would love to have them, but could "delayed" or even decided to be never allowed to protect from "fancy template coding". It would certainly protect me from the latter. So I am not saying Max(T) should be never supported, but generics would already be very useful without and it simplifies the design process a lot (if care is taken that it could reasonably added later). It's just something that could be considered. -Markus On Sunday, July 19, 2020 at 3:17:07 AM UTC+2 Ian Lance Taylor wrote: > On Sat, Jul 18, 2020 at 4:55 AM Markus Heukelom > <markus....@gain.pro> wrote: > > > > Concerning the current generics proposal, was it every considered to not > allow type contracts at all? > > > > No type contracts would mean that generic functions can only use =, & on > variables of parametric types, as these are always available for all types. > Nothings else is allowed. > > > > This would remove the possibility to write generic mathematical > functions, for example. But it is simple and it already enables a lot of > usefulness. Was this considered too restrictive? > > > > Type contracts could optionally be added in a later stage, but at least > at that point we will have a larger body of generic code to work and test > with. > > > > A bonus, disallowing all operations except assignment and address-taking > would maybe also stop abuse of templates in the name of "but it is more > efficient than interfaces" and "fancy coding syndromes". > > I think that for a language like Go any generics implementation must > permit people to write the functions Min and Max. The functions are > trivial, but they are among the first that programmers accustomed to > generics complain about in Go. > > Ian > -- 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 golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/ef98d09e-b11c-47ed-9c15-f16ec39dad3an%40googlegroups.com.