In Go, I'm going to avoid using 'any' as an actual type
utcc.utoronto.ca
In Go, I'm going to avoid using 'any' as an actual type
1–4 of 4 posts
Re: In Go, I'm going to avoid using 'any' as an actual type
#2Don't "go" that far!
Jokes aside tho, I agree—the "anything goes" (pun intended) approach in dynamic programming languages is so annoying. Using "any" in a typed language is like "go"ing back to dynamic style, which many already are trying to escape.
Enough puns for today!
Re: In Go, I'm going to avoid using 'any' as an actual type
#3Is there a difference in how or whether 'any' and 'interface{}' preserve static type information?
i.e., if I implement `identity(a) = a` in a generic way, can I still call identity(duck).quack()?
Re: In Go, I'm going to avoid using 'any' as an actual type
#4Is there a difference in how or whether 'any' and 'interface{}' preserve static type information? i.e., if I implement `identity(a) = a` in a generic way, can I still call identity(duck).quack()?
yes
// You can edit this code!
// Click here and start typing.
package main
import "fmt"
func main() {
duck := Duck{}
identity(duck).quack()
}
func identity[T any](t T) T {
return t
}
type Duck struct{}
func (d Duck) quack() {
fmt.Println("quack")
}
/*
quack
Program exited.
*/