Live data from Hacker News

Reflection in C++

donw.io

1–10 of 40 posts

Re: Reflection in C++

#5
post #4

"is a bad idea".

To clarify, I tried to do something like this back in the 90's and it was _not_ worth the effort.

Using something like Google's Protocol Buffers or a similar system where you generate a standard serialization backend for all the plain old data types you want to send across the network is way less of a pain in the ass.

If you're concerned about the overhead, look at MsgPack or Cap'n Proto - plenty of ways to shave the yak out there without needing to roll your own.

Re: Reflection in C++

#6

There's a typo. "struct Class : pubic Type". It says "pubic" instead of "public". I hope it can be fixed.

I know a C++/Java instructor (with a very dry wit) who would deliberately do this to see if his students were paying attention.

Re: Reflection in C++

#7
post #4

"is a bad idea".

In game development it tends to help solve some common problems.

Games need a lot of iteration, C++ compile times can easily get very long i.e. minutes. You might object that compile times should never be long: "oh this never happens if you do X or Y" but in reality every C++ gamedev shop I've worked at has had long compiles times. Templates and other things of that nature tend to bloat it.

Anyway so reflection helps with:

  - Hot-reloading code
  - Tweaking reflected values at runtime
  - Exposing functions for scripting languages (without having to write lots of repetitive boiler plate code) 
  - Saving / Loading 
(And networking but that's not something I've experimented with personally!) Depending on how it's implemented, at least for games, it's worth it.

Re: Reflection in C++

#10
post #4

"is a bad idea".

In game development it tends to help solve some common problems. Games need a lot of iteration, C++ compile times can easily get very long i.e. minutes. You might object that compile times should never be long: "oh this never happens if you do X or Y" but in reality every C++ gamedev shop I've worked at has had long compiles times. Templates and other things of that nature tend to bloat it. Anyway so reflection helps…

The first two reasons are development/debugging concerns, and the last two are somewhat hacky. Could you elaborate how reflection is the optimal solution for your last two examples?
Post reply on HN