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

What's the point of a singleton when you can just have variables in an anonymous struct at root level, and functions defined at root as well?

  var server struct {
  	host string
  	port string
  }
  
  func serverStart() {
  	server.host = "..."
  	server.port = "..."
  }


When do you call "serverStart()"? If the answer is "eagerly during startup", there's no problem (other than startup time, of course). If the answer is "on demand", now you have a synchronization problem.


Because there are many ways to solve a problem.




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

Search: