Go-internals: Chapter 2, “Interfaces” released
github.com
github.com
package main
import "fmt"
type S struct {
i int
}
func (s *S) foo() {
s.i++
fmt.Println(s.i)
}
type Sarr []S
type I interface {
foo()
}
func doSomething(arg []I) {
arg[0].foo()
}
func main() {
arr := Sarr{S{i: 1}, S{i: 2}, S{i: 3}}
arr[1].foo()
doSomething(arr)
}
I understand why the current implementation of Go doesn't work that way, and that the meta-reason for this not being implemented is the "we don't want generics" attitude, since it would effectively require 2 different compilations of doSomething(), one which accepts a slice of interfaces, which are a (pointer,type) tuple, and one which accepts an slice of this specific struct which happens to actually implement the I interface, and that's a taboo, but come on... it just weakens the idea of interfaces. It could have been done as a compile-time work-around which constructs the slice-of-interfaces argument on-the-fly before calling the function - it wouldn't have been the only magical thing in Go.Is there a language that works the way you describe ?
I wish more microbenchmarks go that deep into IR/codegen analysis (somewhat related : https://mrale.ph/blog/2014/02/23/the-black-cat-of-microbench...).
Is there really much to be learned by analyzing performance in unoptimized pseudo-assembly? It's like looking at JVM bytecode for performance indicators.
I have also written a primer on go-concurrency. https://gist.github.com/rushilgupta/228dfdf379121cb9426d5e90...
Thoughts?
Thanks!