Re: [go-nuts] Re: Named or unnamed struct initialisation? What is best practice?

2017-07-16 Thread Dan Kortschak
Yes, trailing zero-size elements affect the size. https://play.golang.org/p/Ox0FJX3C5V https://github.com/golang/go/commit/6f07ac2f280847ee0346b871b23cab90869f84a4 On Tue, 2017-07-11 at 20:34 -0700, Rader wrote: > I found the position of `[0]byte` in the struct matters.  >  type bar2 struct { >

Re: [go-nuts] Re: Named or unnamed struct initialisation? What is best practice?

2017-07-16 Thread Dan Kortschak
Both are used. On Wed, 2017-07-12 at 11:43 +, Matthew Zimmerman wrote: > Why not use struct{}?  Is what is recommended for maps to notate a > set > (only the keys mean something). -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To

Re: [go-nuts] Re: Named or unnamed struct initialisation? What is best practice?

2017-07-13 Thread Dmitriy Cherchenko
Can you do a test to see if there's a performance difference? -- 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. For more

Re: [go-nuts] Re: Named or unnamed struct initialisation? What is best practice?

2017-07-13 Thread Rader
sure you can. no memory space difference. On Wednesday, July 12, 2017 at 7:44:47 PM UTC+8, Matthew Zimmerman wrote: > > Why not use struct{}? Is what is recommended for maps to notate a set > (only the keys mean something). > > https://play.golang.org/p/fxtEWejqdh > > On Tue, Jul 11, 2017,

Re: [go-nuts] Re: Named or unnamed struct initialisation? What is best practice?

2017-07-12 Thread Matthew Zimmerman
Why not use struct{}? Is what is recommended for maps to notate a set (only the keys mean something). https://play.golang.org/p/fxtEWejqdh On Tue, Jul 11, 2017, 11:34 PM Rader wrote: > I found the position of `[0]byte` in the struct matters. > type bar2 struct { > A int

Re: [go-nuts] Re: Named or unnamed struct initialisation? What is best practice?

2017-07-11 Thread Rader
I found the position of `[0]byte` in the struct matters. type bar2 struct { A int _ [0]byte } differs from type bar3 struct { _ [0]byte A int } see the full example On Wednesday, July 12, 2017 at 10:44:04 AM UTC+8, Rader wrote: > > they both have

Re: [go-nuts] Re: Named or unnamed struct initialisation? What is best practice?

2017-07-11 Thread Rader Lei
they both have the same size, eg. following structs bar and bar2 both take 16 bytes memory on a x64 machine. package main import ( "fmt" "unsafe" ) type bar struct { A int _ bool } type bar2 struct { A int _ [0]byte } func main() { bar := bar{} bar2 := bar2{}

[go-nuts] Re: Named or unnamed struct initialisation? What is best practice?

2017-07-05 Thread snmed
Hi rob Thanks for your response. I didn't know that trick, but it seems to me a little bit ugly to guard fields that way. I will stick to named initialisations and write it as a policy into the style guide. Cheers Am Donnerstag, 6. Juli 2017 02:26:27 UTC+2 schrieb rob rodgers: > > for some of

Re: [go-nuts] Re: Named or unnamed struct initialisation? What is best practice?

2017-07-05 Thread Dan Kortschak
On Wed, 2017-07-05 at 17:26 -0700, rsr via golang-nuts wrote: > type bar struct { >    A int >    _ bool > } or `type bar struct { A int; _ [0]byte }` to avoid the additional byte use. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To

[go-nuts] Re: Named or unnamed struct initialisation? What is best practice?

2017-07-05 Thread rsr via golang-nuts
for some of our sensitive structures that are tricky and have multiple fields of the same type, there is a trick you can use: type bar struct { A int _ bool } see https://play.golang.org/p/rFKGoKq-S9 -- You received this message because you are subscribed to the Google Groups

[go-nuts] Re: Named or unnamed struct initialisation? What is best practice?

2017-07-05 Thread snmed
Okay thanks, as I supposed. Personally i used always named initialisation despite of the overhead, but sometimes I feel the urge to use the short unamed initialisation. ;-) Am Mittwoch, 5. Juli 2017 07:41:04 UTC+2 schrieb Tamás Gulácsi: > > Named. -- You received this message because you are