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
Post a Comment