Reflection vs. Code Generation

Read something yesterday about reflection vs. code generation, on the hibernate site.

It basically said that Smalltalkers prefer runtime reflection and C++ developers prefer code-generation. I’m neither (I was a Java developer before I wrote any Smalltalk, and I’ve never seriously coded in C++). But it occurs that while Java’s reflective capabilities are seriously cool, it’s strong typing means that there is always the slight disconnect that comes from having to use casts and instanceof checks (or always return Object and let the client code worry about it). Reflection in Smalltalk must be pretty fun though!

This is why sometimes reflection is the way to go and sometimes code generation is a better fit. Java sits on the fence on this one (as with so much else).

I’ve more to say on the subject of code generation, but I’m off on holiday now, so unless I get the urge and dive into an internet cafe while there, it might have to wait a week or so.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s