3 ms·
Still much grosser than reflection in other languages.
by Rickasaurus 11y ago
Still much grosser than reflection in other languages.
- kybernetyk 11y agoYes, but reflection usually is an ugly hack anyway and if you have to resort to it something is wrong with your design.
- jjoonathan 11y agoThen 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.
- to3m 11y agoYes. 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.
- devit 11y agoThe 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.
- deleted 11y ago[deleted]
- brucefancher 11y agoLet us know when someone implements anything remotely in the same league as Apple's XCode (based on Interface Builder, which first appear ~25 years ago) for designing GUIs using this technique. The fact that it doesn't exist should tell you something.
- cobalt 11y agoum, no.
- green7ea 11y agoThere are use cases for which reflection is very useful. Things like automatic serialization are an obvious example. There's also automatic printing of complex types, automatic guis (think unity). There are a few use cases which aren't very obvious like having a vector for each element in a structure instead of having a vector of the structure. This greatly improves cache locality and can be a great gain in performance for some applications. Of course this is more introspection which is a specific case of reflection but all these examples are definitely not 'ugly hacks' and could greatly improve C++ as a language.