3 ms·
> Changing the name of a field of a struct can change behavior in another file that never mentions the field by name. I don’t code in go so this looked surpris
by seer 5y ago
> Changing the name of a field of a struct can change behavior in another file that never mentions the field by name.
I don’t code in go so this looked surprising to me. TypeScript has a similar feature regarding types, and it will tell you if you change a field in a record, and that record is actually used in a place where another record with the same fields is asked for.
Kind of surprised go has this problem.
- gpm 5y agoDifference cause of a similar issue. A fair bit of go code relies on reflection to list the fields of a struct and decide what to do, so e.g. if you change the name of a field in a struct and you happened to be serializing the struct somewhere else the serialization will change even though nothing near to the name change suggested that the struct was ever being serialized in the first place. Apart from serialization I've also seen this with ORMs, and some of internal code for metrics. I imagine there are other cases too... but while I currently work in go I'm not really that much of an expert in the language.