2 ms·
I support ports of a Golang library and protocol that did this and I am very tired of having to suffer Go's anemic type system in every other language I work wi
by KirinDave 9y ago
I support ports of a Golang library and protocol that did this and I am very tired of having to suffer Go's anemic type system in every other language I work with.
Please stop infecting us with Go-specific type tags (that btw make the protocol versioning story much more complicated) and either demand Go support generics like every other modern statically typed language, or accept your language is ill-equipped for parsing and check if things = nil a lot more.
Don't advocate for pushing your tooling's problems out on your peers.
- tree_of_item 9y agoAre you referring to majewsky's encoding? How is that a Go-specific type tag? This is a really common encoding of sum types in unityped languages: the presence or absence of a key.
- KirinDave 9y agoThat kind of encoding is only the right call if you want for a message to be a foo, a bar, OR a foo+bar. If you've got an opcode, name it semantically with a name field. If you've got a type to serialize, do it semantically and don't just do like what the library I ported does and put the Golang type annotation in a string. And don't let objects inhabit a fusion like this. It leads to surprising behavior with malformed messages.
- tree_of_item 9y agoYour schema can simply say it is illegal for an object to have both of those tags once. I'm not sure how you'd do any better with a unityped system like JSON. Unless you're advocating using something other than JSON? What do you mean by "do it semantically"? What other alternative is there besides a field for a type tag?
- Vendan 9y agoWhile I don't support what GP is advocating, JSON based apis are often horrible. Apis that return a list of objects or an object based on having >1 or 1 result are just horrifying, and that's just the start of how badly JSON gets abused.
- KirinDave 9y agoI don't disagree that many JSON APIs are poorly designed.
- Rapzid 9y agoThis isn't Golang specific; most statically typed languages are going to fall back on a similar pattern(TypeScript, C#, Javascript, etc). Take a look at AWS's API schemas and you will see. Personally, I loath API schemas designed with the assumption of a dynamically typed language.
- KirinDave 9y agoWhat steams my clams is folks using go type names in f Label fields, or making surprisingly behavior with fusion types that and up actually seeing use in the wild.