Hacker News new | ask | show | jobs
by vortico 3991 days ago
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 = "..."
  }
2 comments

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.