News for hackers. Stuff that matters.
Re:Is Go Duck-Typed? by loopz on Thursday March 05, 2020 @10:48AM (#22494526)
Why do good people downvote what they don't understand?

https://play.golang.org/p/d0TkGTCZa2S

Runtime results in panic:

  4
  Canin
  panic: interface conversion: main.Dog is not interface { 
  Happy() bool }: missing method Happy
  goroutine 1 [running]: main.main() /tmp/sandbox251002434/prog.go:18 +0x200
Using interface casting, Golang do support "duck typing" in similar fashion as ruby's Object class. Here, by convention, the instance of Dog doesn't support "type" Happy(), therefore fails at runtime.

So golang is somewhat dynamic as well, although using interface{} is kludgy and one would want to avoid that and reflection whenever possible.

There are no comments on this comment yet.