6 ms·
I'll be honest, as someone whose non-Python programming (paltry as it is) is mostly done in statically-typed functional languages, I have a bit of a bias agains
by mrtranscendence 6y ago
I'll be honest, as someone whose non-Python programming (paltry as it is) is mostly done in statically-typed functional languages, I have a bit of a bias against Go for the whole generics thing. I'll give it a closer look at some point.
- omginternets 6y agoI gotta be honest, the lack of generics has never bothered me. The type-assertion escape hatch has always been largely sufficient for all but the most performance-critical projects (of which I have exactly 1, and it was a side project), and runtime panics due to failed assertions are quite easy to eliminate via wrapper types. My advice: just go for it. You almost certainly won't miss generics. (Edit: I've broken my own rule and given advice without first asking what kind of programming you do. My assertion holds for most run-of-the-mill stuff, e.g. writing REST interfaces, network servers, etc. If you're within 2-sigma of the industry, you won't miss generics.)
- throwaway894345 6y agoI understand; lots of people have this sentiment. It’s an inconvenience in many cases, but we’re comparing it against Python, which has no type safety at all much less generics (apart from Mypy, which has many, many other issues).
- pjmlp 6y agoAll dynamic languages are generic by default.
- throwaway894345 6y agoIf that's how you define "generic", then Go is also generic by virtue of `interface{}`.
- pjmlp 6y agoNo, because interface{} in an empty type that needs to be type cast to the actual type before use. Dynamic languages do that implicitly. Implement max in Go with interface{} without casts and reflection: def max(a, b): if a >= b: a else: b
- throwaway894345 6y agoI'm not aware of any definition of 'generic' that prohibits casting. It certainly seems like a very arbitrary condition. Basically I'm familiar with two definitions: 1. The abstract idea of writing an algorithm that supports a variety of types. This allows for casting, reflection, dynamic typing, etc. 2. The specific idea of a type system that allows for parameterized types (aka "typesafe generics"). This definition excludes castng, reflection, and dynamic typing. Typically "typesafe generics" is what people talk about when they discuss "generics", but since you chose to pick the "dynamically typed languages are generic" nit, I assumed you were talking about (1).