News for hackers. Stuff that matters.
Re:Cost of enum-to-string: C++26 reflection vs. the old ways by bluGill on Wednesday May 13, 2026 @10:25AM (#48122361)
It is powerful, but I'm not sure it is a good idea. Other languages have it, and there is lots of experience in all the ways things go wrong in the real world. I'm inclined to say you should hand write this code because eventually you will discover something weird anyway.
Re:Cost of enum-to-string: C++26 reflection vs. the old ways by electroly on Wednesday May 13, 2026 @10:48AM (#48122665)
Can you give an example of a language ecosystem that went with reflection-based JSON serialization/deserialization and then went on to regret it? I can't think of any, and don't agree with your conclusion. It works great, and manually writing serialization and matching deserialization code is terrible, annoying, error-prone work.
Re:Cost of enum-to-string: C++26 reflection vs. the old ways by maccard on Wednesday May 13, 2026 @11:31AM (#48123252)
I disagree. Rust's defacto default is serde, golang comes with batteries included, dotnet/java have had it for _years_, and all the dynamic languages do it.
Re:Cost of enum-to-string: C++26 reflection vs. the old ways by SuperV1234 on Wednesday May 13, 2026 @10:47AM (#48122663)
I think this is a very bad take -- once you write it by hand you have to manually keep it in sync with the actual struct and ensure you made no mistakes. Reflection guarantees 1-1 future-proof mapping with the actual C++ struct, avoids boilerplate, and ensures that the serialization logic is correct.
Re:Cost of enum-to-string: C++26 reflection vs. the old ways by bluGill on Wednesday May 13, 2026 @11:55AM (#48123592)
The protocol is important though, not the internal structure. When you only have exactly one version of a program talking to the same version of itself you don't care. However when you are mixing versions or worse programming language (and thus can't mix structs which are implementation details of your language) the protocol is what matters.

That is if you are worried about doing this by hand reflection is not the answer, something like protobuf where your data structures are generated is the answer.

Re:Cost of enum-to-string: C++26 reflection vs. the old ways by gpderetta on Wednesday May 13, 2026 @03:39PM (#48126446)
I completely understand your point. Then again you might be able to use reflection to verify that your manually rolled implementation actually serializes all fields.