Go Data Structures: Interfaces (2009)
research.swtch.com
Go Data Structures: Interfaces (2009)
1–10 of 80 posts
Re: Go Data Structures: Interfaces (2009)
#2Re: Go Data Structures: Interfaces (2009)
#3A quirk of Go is that I can cast a `[]string` to `interface{}`, but I cannot cast `[]string` to `[]interface{}`. This blog post is my go-to explanation for why the second is not possible but the former is.
Re: Go Data Structures: Interfaces (2009)
#4A quirk of Go is that I can cast a `[]string` to `interface{}`, but I cannot cast `[]string` to `[]interface{}`. This blog post is my go-to explanation for why the second is not possible but the former is.
Re: Go Data Structures: Interfaces (2009)
#5A quirk of Go is that I can cast a `[]string` to `interface{}`, but I cannot cast `[]string` to `[]interface{}`. This blog post is my go-to explanation for why the second is not possible but the former is.
Surely that's just contravariance, though? You can't cast []string to []any because that would allow you to write non-strings to it.
Re: Go Data Structures: Interfaces (2009)
#6A quirk of Go is that I can cast a `[]string` to `interface{}`, but I cannot cast `[]string` to `[]interface{}`. This blog post is my go-to explanation for why the second is not possible but the former is.
Is that really a "quirk" of specifically Go? I am pretty sure Java--the implementation of which defined a lot of how numerous languages handle this kind of thing--has the same behavior: you can cast String[] to Object, but not Object[].
object[] array = new string[10];
// throws a run-time exception
array[0] = 10;Re: Go Data Structures: Interfaces (2009)
#7Generally speaking the Go compiler seems to have trouble with inlining, PGO (profile guided optimization) can help though.
Re: Go Data Structures: Interfaces (2009)
#8Re: Go Data Structures: Interfaces (2009)
#9If you are mindful of performance, one thing to be careful of, is that interfaces often prevent inlining and can cause performance issues. Generally speaking the Go compiler seems to have trouble with inlining, PGO (profile guided optimization) can help though.
not "have trouble", a deliberate design to keep compile times fast and (emitted) code size reasonable
Re: Go Data Structures: Interfaces (2009)
#10If you are mindful of performance, one thing to be careful of, is that interfaces often prevent inlining and can cause performance issues. Generally speaking the Go compiler seems to have trouble with inlining, PGO (profile guided optimization) can help though.