Home > Great Links > A nice discussion on Jeremy’s blog about generated code

A nice discussion on Jeremy’s blog about generated code

Jeremy has a post going on the quality of generated code. I liked Frans Bouma’s comment below. I am reproducing it word by word here, as no one generally reads scrolls down to the bottom of comments in a long discussion.

"Of course, if the template sucks and the meta data is lacking, the generated code will suck as well, at least on the scale of suck used by the reader of the code.

So to get good code generated, you need to have good templates AND good meta-data. If either one of them (so a good template with sucky meta-data also gives bad results) is lacking in some area, you won’t get stellar results.

That doesn’t mean the concept of code generation sucks. the thing with code generation is that, IF the template and meta-data is OK, a code generator will beat any developer, simply because it won’t make mistakes every X lines of code and won’t get bored so it will take shortcuts nor will it get tired of the repetitive piles of goo it has to write.

I must say that I always find it a little funny that a developer declares code generation not that great a technique, so in other words: he himself is always capable of writing better code than a code generator can.

the thing is: that’s a lie. You can’t beat a code generator with proper templates and OK meta-data, simply because the code generator won’t make errors.

But again: make no mistake: it is essential that the templates and meta-data are OK. this means that the templates have to be created from hand-written code, then the generated code has to be tested, profiled, checked for lame mistakes. This process has to be repeated till there are NO BUGS in the templates left and no lame lines of code left in the templates which make whinetools like fxcop throw up.

Code generators are just typing machines: they do the typing for you. If you look at them that way, there’s no magic, they’re just handy because who wants to type for weeks after weeks if a code generator can do that in a minute?

MS’ internal code generator isn’t that great, as it doesn’t use templates, it uses the CodeDOM. This isn’t a great decision because you can’t alter the template to make it better.

"
Wise words. But again: make no mistake: it is essential that the templates and meta-data are OK

Advertisements
Categories: Great Links
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

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

WordPress.com Logo

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

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: