go - Why are struct literals "literal" -


in golang struct literals?

why following literal though there variable? , aren't structs literally variable, when not const? how make sense.

mytype{field: var) 

it has variable , yet it's "literal"?

also why called "struct literal" when first initialize it?

programming languages use word "literal" when referring sytactic ways construct data structure. means it's not constructed creating empty 1 , adding or subtracting go.

compare:

mytype{field: myvariable} 

to

var x = new(mytype) x.field = myvariable 

the benefit code's appearance reflects data structure in way. downside have know layout in advance , have content initialized already, not possible, if instance, you're constructing map unknown keys.


Comments

Popular posts from this blog

node.js - How to mock a third-party api calls in the backend -

node.js - Why do I get "SOCKS connection failed. Connection not allowed by ruleset" for some .onion sites? -

matlab - 0-by-1 sym - What do I need to change in order to get proper symbolic results? -