|
|
|
|
|
by burntsushi
4291 days ago
|
|
> Performance: if you replace all generics with interface{}, you get performance that is at better or equal to current Go code. That is incorrect. Using `interface{}` incurs a significant performance penalty at runtime because you end up boxing everything. For example, you cannot cast a `[]interface{}` to an arbitrary `[]A`. In other words, no, `interface{}` is not `void*`, sorry. If it was, Go would not be memory safe. (See golang.org for their definition of memory safety. It is strictly superior to a language like C, but e.g., less than a language like Rust.) |
|
AFAIK it's not possible to write generic Go code without `interface {}` (or, alternatively, duplicating the code for each type).