11 ms·
As a side note, Java also didn't ship with generics. Java was released in the mid 90s and didn't have generics until about 10 years later with version 5. This t
by correct_horse 7y ago
As a side note, Java also didn't ship with generics. Java was released in the mid 90s and didn't have generics until about 10 years later with version 5. This timing should feel familiar - Go first appeared ~10 years ago in 2009.
You may remember that in Java 1.4, `get`ting from collections (e.g. ArrayList) always returned Object, which you were expected to cast to their runtime type (or a class that their runtime type inherits from). I was young at the time, correct me if I'm wrong. Contrast this with Go's solution, which seems to be user-inaccessible compiler magic. I much prefer Go's solution to Java's, but I also like generics.
- saagarjha 7y agoI really hate user-inaccessible compiler magic. Java had its fair share of that, but Go seems to take it even further :(
- Skunkleton 7y agoI think compiler magic is pretty great. Hotspot is a pretty magical compiler. Go is less magical IMO because it is AOT compiled.
- saagarjha 7y agoBy compiler magic I really mean syntax reserved to the language itself; for example, Java's String having extra operator superpowers or Go's generics that are only available to a chosen set of standard collections.
- antoinealb 7y agoI think you can do the same in Go, using the empty interface (that can represent any type) and then having the user cast it to the correct type. Unfortunately this is not type safe, and type safe generics in go, such as maps is only available to the compiler.