John Lam 1997 — 2026

Dave Thomas on Code Generation

Dave Thomas, of Pragmatic Programmer fame, has some thoughts on code generation in this interview on the Code Generation Network (CGN). I didn’t know that CGN existed until I found a single referrer in my server logs tonight.

IMHO, these are the highlights of the interview:

  • Justifying code generation using his Don’t Repeat Yourself (DRY) principle that I first read about his book.

  • Highlighting the “bad smell” that taints code generation because of one-shot wizards

  • How code generation is just another tool in your toolbox - do not attempt to generate 100% of your app

Excellent interview and well worth the read.

2 archived reader comments

Jason Langston (2003-04-29)

I’ve read for months with only mild interest your comments about AOP and code generation (they’ve seemed a bit esoteric for a corporate app drone like myself). This article has finally opened my eyes to what you’ve been saying all along. The lightbulb has gone off, and you now have a “believer”. Keep the info coming. Jason

Eric Parker (2003-04-30)

“Once you start working in dynamic languages such as Ruby, code generation takes on a whole new meaning, as you can effectively extend the language at runtime from within…” The purpose of code generation is to express a problem using a convenient abstraction that isn’t easily supported by your implementation language. I think this statement is an important endorsement of extensible languages: rather than having to resort to code generation, just extend the language to support the abstraction you need. However one must be careful not to abuse the privilege - it seems it would be all too easy to descend into a quagmire of undecipherable gobbledygook. There is a cost associated with using language features: readability and understandability. I rarely use operator overloading in C++ for this reason; I find “Concatenate(a,b)” more transparent than “a+b”. Two parties must have a common language in order to communicate. This is why software metaphors can be so powerful (see Code Complete by Steve McConnell) - they provide a shared experience that helps guide us through the design. I think an important challenge for code generation and extensible languages is how you achieve expressiveness while maintaining clarity.