Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The problem is you don't get compile time checking. If you forget that Foo implements IBar and change the method doSomething() so that it no longer implements IBar you only find out with runtime bugs.

I really like Go but it's been a while since I used it. Someone correct me if I'm wrong here.



  package main
   
  type IBar interface {
  	doSomething()
  }

  type Foo int

  func (f Foo) doSomething() {
  	println(f)
  }

  func test(b IBar) {
	b.doSomething()
  }

  func main() {
	f := Foo(1)
	test(f)
  }
Compile, run:

  1
Rename doSomething function to doSomethingElse. Compile:

   test.go:20: cannot use f (type Foo) as type IBar in function argument:
	Foo does not implement IBar (missing doSomething method)


Unit testing to the rescue.


More like just compiling =)




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: