3 ms·
The article is about compile-time reflection, which is not nearly as useful as what the Wikipedia article you linked is about. It's only upside is that it is "z
by weinzierl 2y ago
The article is about compile-time reflection, which is not nearly as useful as what the Wikipedia article you linked is about.
It's only upside is that it is "zero cost" by some definitions of cost.
Runtime reflection on the other hand is useful but it also puts up obstacles not easy to overcome. For example it is one major reason we still have no decent ahead-of-time compilation in Java.
- flohofwoe 2y agoI'm in the opposite camp, runtime reflection is useless, and almost always points to a design flaw while compile time reflection is actually useful (for obvious things like automatically building a serialization layer or an UI which represents the type, or building types from other types). I'm sure that C++26 has implemented it in a way which is highly unpleasant to use though ;)
- deleted 2y ago[deleted]
- jcranmer 2y agoThe element of runtime reflection that is the most useful is something along the lines of "here's function, here's a list of arguments, go call this function with those arguments".
- xmcqdpt2 2y agoHaving to do this by reflection is a problem in principle solvable by types. Here is a function of type (A, B, C) => R, and here is a tuple of arguments of type (A, B, C), go call this function with those arguments. Most programming languages make it hard to easily express those constraints so reflection is used instead.
- pjmlp 2y agoWe have add decent AOT compilation in Java almost since 2000, with Excelsior JET being one of the first vendors to offer it, but few are willing to pay for such tools. Also I consider ART, GraalVM and OpenJ9 decent enough as free beer AOT.
- nickelpro 2y agoCompile-time reflection is by far the most useful It replaces the plethora of code generators that currently surround C++ like flies
- badmintonbaseba 2y agoYou can build runtime reflection on top of compile time reflection, it's impossible the other way around. Compile time reflection is a superset of what runtime reflection can do.