Hacker News new | past | comments | ask | show | jobs | submit login

Go has methods only to satisfy interfaces, which are different than most other language's interfaces and a very crucial part of what gives the feel of Go. No methods, no interfaces, therefore if Go were to have no methods, it would have to offer the same features and language feel by some other mechanism. Perhaps there are many ways to do that, but the only way I can think of is allowing for code like this:

  type IPConn struct {
  	ip Ip
  	// contains filtered or unexported fields
  }
  
  func Write(i IPCconn, buf []byte) (int, error) { /* implementation */ }
  
  type File struct {
  	name string
  	// contains filtered or unexported fields
  }
  
  func Write(f File, buf []byte) (int, error) { /* implementation */ }
  
  func WriteString(w T, s string) (int, error) {
  	return Write(w, []byte(s))
  }
Please note that there are no explicit interfaces, but WriteString takes an implicit Writer. You can do that in C++ with overloaded functions and templates (not overloaded functions alone), but templates are an example of higher order type inference, which was the point I was trying to convey.



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

Search: