This article highlights very well why designing a programming language without generics is a mistake. Adding it after the fact is not trivial, especially if you have high standards wrt simplicity and non-redundancy.
Generics aren't ready for Go
11–20 of 238 posts
Re: Generics aren't ready for Go
#12This article highlights very well why designing a programming language without generics is a mistake. Adding it after the fact is not trivial, especially if you have high standards wrt simplicity and non-redundancy.
Re: Generics aren't ready for Go
#13Re: Generics aren't ready for Go
#14Maybe a Go programmer can enlighten me - without generics, how can you have data structures implementations that can contain more than one type? Do you have to have one linked list implementation for every type in your program? Do you have to abandon type checking by using an equivalent of void pointers? Or is the type system smart enough that you'd never need generics in the first place?
If you really want high performance with many different types of a function, its a case of copy-paste-modifying your code.
Its a language that is straight-forward, its the antitheisis of tmtowtdi.
Re: Generics aren't ready for Go
#15Re: Generics aren't ready for Go
#16Maybe a Go programmer can enlighten me - without generics, how can you have data structures implementations that can contain more than one type? Do you have to have one linked list implementation for every type in your program? Do you have to abandon type checking by using an equivalent of void pointers? Or is the type system smart enough that you'd never need generics in the first place?
First go does have generics. It just doesn’t have user defined generics. But to answer your question go has really mediocre support for a wide variety of problems. Some that burn me a lot is support for future/promises and support for modern lock free algorithms. So you end up either writing non-optimal replacements, losing type safety or in some case code generation is used.
This doesn't make sense in Go. Nothing is asynchronous in Go, everything is blocking. You use goroutines to execute multiple tasks at the same time. That's a big part of what makes Go simple: it's a lot easier to understand sequential code than spaghetti callbacks and promises (it's somewhat similar to async/await in the JavaScript world).
Re: Generics aren't ready for Go
#17I don't understand how not having generics is at all acceptable. But maybe that's because I come from a functional programming perspective.
Re: Generics aren't ready for Go
#18Re: Generics aren't ready for Go
#19I don't understand how not having generics is at all acceptable. But maybe that's because I come from a functional programming perspective.
Re: Generics aren't ready for Go
#20I keep thinking they could add macros instead but I guess the C++ version is too much history for them to be associated with. It would basically be like code generation at compile time, except much cleaner than the current, version-specific mess of tools.