2 ms·
I 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 mu
by throwaway894345 6y ago
I 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).