3 ms·
Aesthetically, I consider such JSON structures degenerate. It's akin to building a ECMAScript app where every class and structure is only allowed to have one me
by phlakaton 7mo ago
Aesthetically, I consider such JSON structures degenerate. It's akin to building a ECMAScript app where every class and structure is only allowed to have one member.
If you want tagged data, why not just pick a representation that does that?
- foltik 7mo agoBecause (imo) the goal should be to minimize overall complexity. Pulling in XML and all of its additional complexity just to get a (debatably) cleaner way to express tagged unions doesn’t seem like a great tradeoff. I also don’t buy the degenerate argument. XML is arguably worse here since you have to decide between attributes, child nodes, and text content for every piece of data.
- phlakaton 7mo agoDepends on the application, I suppose. For OP's application, pulling in XML is no trouble and gives you a much better solution for typed unions. To get better than XML, I think you're looking at something closer to a Haskell- or LISP-embedded DSL, with obvious trade-offs when it comes to developer ecosystems and interoperability.
- imtringued 7mo agoIf your concern can be addressed by using an array, I don't really find it to be such a compelling argument.