4 ms·
Try representing JSON in C++. Sure, you can figure out a way that works, but the C++ code for printing out the JSON is much uglier than a language with tagged u
by lostdog 3y ago
Try representing JSON in C++. Sure, you can figure out a way that works, but the C++ code for printing out the JSON is much uglier than a language with tagged unions.
- pjmlp 3y agoThat is a consequence of lack of reflection, not sum types.
- ansgri 3y agosum types can often eliminate the need for reflection, and can have lower runtime cost.
- pjmlp 3y agoCompile time reflection doesn't have runtime cost.
- lostdog 3y agoCompile time reflection doesn't work for this case.
- pjmlp 3y agoTemplate metaprogramming techniques as poor man's reflection prove otherwise. Additionally that is one of the examples on the ongoing C++ reflection papers. Then there are a couple of examples in D, Common Lisp, Scheme, C# code generators.
- lostdog 3y agoNo? A JSON object could have any type at run time. You cannot do anything at compile time to figure out the right type. Please point to a specific library if you disagree.