4 ms·
Lack of generics can make it harder to write cleanly reusable modules in Go. I've noticed gophers are often less allergic to copy pasting code with tweaks (as l
by dcsommer 11y ago
Lack of generics can make it harder to write cleanly reusable modules in Go. I've noticed gophers are often less allergic to copy pasting code with tweaks (as long as it isn't too many lines) and don't mind rewriting similar code if it is obviously correct. It was a bit of a culture shock for me at least.
- deleted 11y ago[deleted]
- _ak 11y agoYou confuse parametric polymorphism with reusability. The former is merely one of several ways to achieve the latter. The Go way for reusability usually consists of interfaces.
- dcsommer 11y agoCode reuse is totally possible in Go. I never said otherwise. However, there may be unnecessary ergonomic and safety issues due to lack of generics. In particular, you may end up casting / type asserting when you really shouldn't have to.
- deleted 11y ago[deleted]
- dragonwriter 11y agoInterfaces and parametric polymorphism are not alternative approaches to solving the same problem, which is why many languages that feature parametric polymorphism also feature interfaces or similar constructs [0] (and why some languages that had interfaces for a long time later added parametric polymorphism [1].) [0] e.g., Haskell typeclasses [1] e.g., Java