I wish go's type inference worked inside struct literals. Filling out 
config structs would be so much easier if this worked:

type Config struct {
  Runtime struct {
     Debug bool
  }
}
c := Config{
  Runtime: {
    Debug: true,
  },
}

^^ why can't this work?  It seems unambiguous.

The initial Config{ defines the type and tells the compiler exactly what 
everything inside it must be....

The reason that I wrote the struct that way is that it makes it very easy 
to read when the struct gets bigger. The sub-structs become basically just 
namespaces on the fields they encompass.  But if you then have to write a 
literal by redefining the struct, the literal becomes impossible to read


c := Config{
  Runtime: struct { Debug bool }{
    Debug: true,
  },
}





-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/cfafda6e-0d1c-4a38-8ed7-b5c8eda2e446%40googlegroups.com.

Reply via email to