[fpc-devel] .NET Reflection vs RTTI
Michael Van Canneyt
michael at freepascal.org
Tue Nov 20 11:42:07 CET 2007
On Tue, 20 Nov 2007, Thorsten Engler wrote:
> > Private and protected are not your business in the first
> > place, exposing it through RTTI or whatever is bad design. Public, OK.
>
> The class itself should have access to that information. It can then use it
> to e.g. stream the contents of all/some of it's private fields to/from a
> stream.
Serious:
This is exactly my point: You will have to code this yourself anyway,
making the whole idea of introspection superfluous because the introspection
misses the semantical information which is needed to be able to code that.
Only the programmer knows which private fields must be stored and which not.
You cou could store that in additional attributes, but then you would need
custom code to check those attributes anyway, since no framework exists to
interpret the meaning of your attributes: again error prone.
And to be able to store it optimally, he needs more semantical knowledge.
You can of course do the brute force attack, but that is so hideously slow
that it is not usable in practice. Again, this cannot be stored in your
attributes. (probably you could, but then you're coding again, just
metadata this time, for which additional custom code is needed - again.)
Scepticism/Sarcasm:
So, my personal conclusion:
Introspection just saves a bit of typing because of the easy access,
but that is about it. It doesn't make code safer, because if the
programmer specifies the wrong attribute it fails anyway.
Serious again:
And the easy access: I'm all for it, I have it in my agenda, as I said.
That it should include maybe records and other types: No problem.
(this is the RTTI scope, after all)
Metaphysical:
I'm not proposing we go back to the stone age, and use hammer and chisel
to carve messages in rock tablets. But I remain sceptical of many
"innovating" things. IT is very prone to hypes, so I judge each "new"
thing by it's merit. For introspection and custom attributes this
happens to be rather low, becuse I think it's totally missing the
point since it cannot include semantical data needed to make it
really useful.
And that's the last thing I will say about it, the next thing
will be simply showing the easy access code. The 'better' RTTI
is for the compiler people to implement.
Thorsten, if you want to reply, please in private.
Sorry if I offended someone, no offense was meant.
Michael.
More information about the fpc-devel
mailing list