Remix.run Logo
reactordev a day ago

struct tags greatly reduce the boilerplate code required to map fields to fields. It’s really quite novel once you understand it.

masklinn a day ago | parent | next [-]

> struct tags greatly reduce the boilerplate code required to map fields to fields.

Are you somehow under the impression that Go is unique in having a terse way to map fields to fields?

> It’s really quite novel once you understand it.

It's the opposite of novel, putting ad-hoc annotations in unstructured contexts is what people used to do before java 5.

reactordev a day ago | parent [-]

No, not at all, but considering C has no such thing, I’ll take it.

jlouis a day ago | parent | prev [-]

It's not very novel. There's far better ways of solving this than allowing a random string to be embedded as aux information to a struct field. Examples: F# type providers, or OCamls PPX system for extending the language in a well defined way. Macro rewriting systems also allow for better safety in this area.

This allows you to derive a safe parser from the structural data, and you can make said parser be really strict. See e.g., Wuffs or Langsec for examples of approaches here.

reactordev a day ago | parent [-]

I’m not disagreeing that there are better ways to solve this given how other languages have implemented theirs but considering the constraints they had at the time the Go team designed this, it allowed them to implement marshaling fairly easily and leaves it open for extensions by the community.

maleldil a day ago | parent [-]

> considering the constraints they had at the time the Go team designed this

What constraints? Ignoring decades of programming language developments since C89?