Maybe 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?
You use an interface. Golang use duck typing. It is very flexible and very simple. (Some times too simple)
Generics aren't ready for Go
31–40 of 238 posts
Re: Generics aren't ready for Go
#32This article is wrong in many ways, but I thought I'd point out this particular one. There are many really weird warts in Go, in fact its about average in "wartiness". Here is one example https://dave.cheney.net/2017/08/09/typed-nils-in-go-2
Go biggest advantage isn't the language, its the decent documentation and standard library design. The language is a bit mediocre. I wish the Go community accepted this and moved on - a mediocre language with good documentation and well done standard library is still an acceptable contender since so many other languages get those two wrong.
Re: Generics aren't ready for Go
#33Uhg such programming language Stockholm syndrome. You could apply this fallacy to any feature. The lack of modules and a performant garbage collector also bred creative solutions in previous Go releases, but that doesn't mean that adding those was a bad idea.
Re: Generics aren't ready for Go
#34Maybe 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?
Go has a kind of generics that also maps cleanly to machine-level generics: interface{}, which is like void* in C. Whereas all the other kinds of generics, I believe, can't offer this quality. They require a lot of machine code instanciations (like C++'s template system). Or at least, in the case of virtual functions ("dynamic polymorphism" with VTables), they cause more brittle abstraction boundaries. Think how in C…
Even on C++ this is be eventually a thing of the past, after modules get finally adopted.
Using how C++ currently does as argument against generics is a pretty weak argument, given the various ways to implemente them since CLU and ML introduced generic programming into the world.
Re: Generics aren't ready for Go
#35I don't understand how not having generics is at all acceptable. But maybe that's because I come from a functional programming perspective.
I don't miss them - it's just a different way of programming but I've not ran into a problem that I couldn't overcome because they are missing.
OTOH, I've shot myself in the foot quite a few times with Generics.
Honestly, just _try_ it for longer than an exploratory session. Try to build something big with it, and see if you still miss it.
Re: Generics aren't ready for Go
#36I 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.
Macros are another can of worms. Even if they're AST-aware like in Rust, you can do very complicated stuff with them and they are very hard to read/write/debug. This would kill the advantage that it's very hard to write obscure Go code.
But it's very easy to spread that Go code into tens of Kloc.
The amount of error handling and if constructs make me feel as if I am readying assembly: predictable AF, but it doesn't help because the volume of the code is huge.
Re: Generics aren't ready for Go
#37Earlier quoted context omitted.
>Some that burn me a lot is support for future/promises 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).
Yet open up nearly any large golang codebase and you’ll find a channel being used to return a single answer response in the future.
Re: Generics aren't ready for Go
#38I don't understand how not having generics is at all acceptable. But maybe that's because I come from a functional programming perspective.
It's because Go is a brutalist hipster language - simplicity above utility. Forget a lack of generics, you don't even get proper error messages.
Re: Generics aren't ready for Go
#39This 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.
It seems crazy to me that language designers of modern statically typed languages wouldn't go for the state-of-the-art. I see the comments about simpilicty, but generics makes [working with abstract types] simpler (in my humble opinion, of course).
Re: Generics aren't ready for Go
#40Earlier quoted context omitted.
>Some that burn me a lot is support for future/promises 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).
Yeah, and that's why Go code is a spaghetti of communicating via channels, rather than callbacks.