Hacker News new | ask | show | jobs
by jjoonathan 3865 days ago
Then why do the solutions people use to work around the absence of reflection always seem to suck so much? They're (in some combination) verbose, highly un-DRY, require spectacular feats of type-system-fu, and at the end of the day they deliver capabilities that come up laughably short of their competition in other languages. I'm still waiting for a member of the "Reflection is Useless" crowd to show me a serialization framework on par with what I find in Java (100% DRY, 100% automatic for POD, 100% override-able without a type repository, 100% devoid of compiler/linker trickery). Or a desktop framework that offers UI design capabilities comparable to the introspection-based ones I find in ObjC, C#, or whatever you want to call the home-brew C++-with-reflection that Qt uses.
2 comments

The best apprach is to have "reflection" (really, access to the compiler AST or IR) at compile time and generate code from this, since that minimizes the run-time overhead.

See Rust's serde for an example of that for serialization.

Yes. And don't just think about how messy the homegrown alternatives are - note how much effort people go to add them in! It's just such a useful thing to have - serialization; logging; UI generation; automatic scripting language bindings - and that's why people bother.