DEV Community

Discussion on: Golang for Experienced Developers

Collapse
leob profile image
leob • Edited on

"Here is What Go Lacks" - I'd like to add a 5th point:

Go does not support Generics!

This makes it effectively impossible to write generic functions/methods that handle a collection of objects of any type/subtype, and is the kiss of death for an FP (functional programming) style approach to coding (map/filter/reduce and so on).

Essentially this means that with Go you're forced to code imperative loops, ad infinitum, till you see blue in the face ... a big drawback compared to a language like Rust.

I really hope they're going to address this in a future Go version. I mean, I do appreciate the ethos of "Go keeps it dead simple" (and IMO the learning curve of Rust is way too steep), but lack of support for Generics isn't about keeping things simple, rather it's dumbing down things way too much.

Collapse
bastianrob profile image
Robin

I'll add another

  1. Only primitive type constants
  2. Lack of default constructor for struct
  3. Weird interface{}
Collapse
leob profile image
leob • Edited on

Yeah it's funny how cobbled together the language seems, and how poor the type system is, but it's still hugely popular because people get stuff done with it - you can't really argue with that ...

The above 3 points are valid concerns, but for me it's the lack of Generics that sticks out like a sore thumb.

(one big reason why Go is so popular are the intuitive and incredibly useful Go Routines - another reason is its well-conceived and well-executed Standard Lib)

Thread Thread
bastianrob profile image
Robin

TBH I've had my share of probelm with absence of generic in go too.

Oftentimes find myself cooy pasting another part of my code with same functionality but different type.

But go is simply too simple and too opinionated. Everybody's codestyle are roughly the same and it's super easy to pick up on go projects codebase than, say, JavaScript.

Thread Thread
leob profile image
leob • Edited on

Exactly! You end up copy/pasting and rewriting loops endlessly, because there are no Generics.

I think it's a good thing that Go is simple, that's the philosophy of the language and they should stick to it. I've also looked at Rust, and it's brilliant but it is HARD.

But, they should REALLY consider adding generics to Go ... if they're allowed to add one and only one thing to the language, generics it should be.

Thread Thread
livesamarthgupta profile image
Samarth Gupta Author

I guess generics are on their way in Go. Check freecodecamp.org/news/generics-in-...

Thread Thread
leob profile image
leob

Yeah I heard they were working on it, great to see that it's coming!