|
Kevin Gillette |
at Dec 5, 2013 at 5:20 am
|
⇧ |
| |
If we pretend that the proposal (and proposed syntax) were universally
favored, it'd result in an inconsistent grammar. Consider:
// the brace must go on the same line as the tag
// unless a special (inconsistent) exception were made
type Thing struct `tag:"thing"` {
Field1 int `tag:"stuff"`
}
type Integer int `tag:"other thing"`
In the above, the tag in the struct case goes after the struct keyword. For
primitive types, it'd Go after the type definition. Really, the only
consistent approach is to put the tag after the entire type definition, and
that'd result in:
type Thing struct {
Field1 int `tag:"stuff"`
} `tag:"thing"`
That looks a bit like typedef's in C, and typedef'd structs are pretty ugly.
On Wednesday, December 4, 2013 8:03:04 AM UTC-7, Matt Sherman wrote:Struct (field) tags have proven very useful, and I am curious whether
there has been consideration of offering the same at the type level? Would
be handy for the stuff I am doing on gen<
https://github.com/clipperhouse/gen>
.
Not sure where it would go syntactically, but something along the lines of:
type Thing struct `tag:"thing"`
{
Field1 int `tag:"stuff"`
}
type Another []string `tag:"foo"`
A bit of metadata would go a long way. Could apply to any type def, not
just structs. Was there a particular design decision to only support struct
fields?
--
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+unsubscribe@googlegroups.com.
For more options, visit
https://groups.google.com/groups/opt_out.