Recently I came across a wiki that attempted to discuss the merits of code generation, with the initial postulation that Code Generation is a "Design Smell"... IE, that if you have to do code generation, then there is something wrong with the design of the language you are using.
Code generation is really just another name for a compiler. And we've been using compilers for a long time. A C++ compiler is just a code generator that creates lower level code (C or directly to assembler/machine code) from a description you give it (the C++ code). That's really not so much different than, say, CodeCharge which lets you design visually but stores the definition as an XML file which is then "compiled", IE code is generated on demand.
I don't think anybody that is against Code Generation could possibly say that a C++ compiler is bad.
But look at the progression of compilers. The first compilers were made because people realized that a lot of the machine code they were writing was similar. So they created higher-level languages to represent these similarities as language features that could be compiled to the lower level machine code. IE, a code generator.
So the concept of Object Oriented Programming comes along. Languages like C had no way of expressing this natively. But you could do OOP with C by coding it by hand. And so once again you have these similar bits of code being written all the time. And one day somebody decided, lets represent those patterns with an even higher level language, and C++ was born. Initially, C++ compiled into C which was then compiled in machine code. You would think the anti code generation people's heads would explode at the thought.
Right now we have a generation of web applications being written with just tons of similar code being written. Design patterns like MVC and CRUD and boring but necessary security checks in data forms etc etc. So we have all sorts of code generators, some compiler like, some on the fly, some using frameworks.
What we really need, it seems, is the next generation of languages that expresses these web application requirements as part of the language. Then we can make interpreters and/or compilers. And make that language a standard instead of having dozens of different incompatible frameworks and code generators.
Let the cycle begin again!
1 comment:
Thanks for writing this.
Post a Comment