HTML Generation vs. Code Generation
Before talking about application code generation, let’s have a closer look at the generator techniques we are all familiar with; let’s examine html generators.
In the old days, at the beginning of the internet time age, some geeks discovered very fast the power of generators. The first generators were written in C or Perl and got famous under the term CGI.
Later some template language based generators like ASP and PHP appeared. A lot of people started to use them. The ice for html generation was broken.
Later was recognized that it wasn’t really a good idea to mix code and design at one place. That’s one point what ASP.NET is about. Code and Design are now separated into two files. In addition an even higher abstraction level was introduced by using the OO features of the .NET Framework. We are now able to add objects like tables, rows and cells to controls without using a template. Due to this fact it is possible to create the output for different targets like Internet Browsers and mobile devices.
Let’ summarize this in a fact sheet and compare it to active code generation:
|
|
CGI |
ASP/PHP… |
ASP.NET/code behind |
|
name proposal |
script |
template language |
object model |
|
Code looks like |
write ("<table>"); write (" <tr>"); write (" <td>"); write (" "+content); write (" </td>"); write (" </tr>"); write ("</table>"); |
<table> <tr> <td> <%=Content%> </td> </tr> </table> |
Table table = new Table(); TableRow row = new TableRow(); TableCell cell = new TableCell(); cell.Controls.Add (new LiteralControl(content)); row.Cells.Add (cell); table.Rows.Add (row); this.Controls.Add (table); |
|
viable for html creation |
yes |
yes |
yes |
|
ease of maintain source |
easy |
easy |
easy |
|
ease of pasting in sample code |
difficult |
easy |
nearly impossible, aside from controls.add(new literalcontrol(“…samplecode..”)) |
|
presentiment of output |
yes |
yes |
no |
|
abstraction level |
low |
low |
high |
|
other benefits |
total flexibility |
easy to read while developing |
output to multiple targets |
|
application range |
closed application |
template based html generation |
user controls (compiled) |
|
|
Symmetries to application code generation/ using these to generate code instead of html |
|
CGIA |
tier generator |
tier generator |
code munger |
|
KaDGen |
brute force |
not mentioned * |
codeDOM |
|
|
|
|
|
|
primary domain (IMHO) |
wizard |
template based code generation |
on the fly code generation, powerfull in conjunction with parser, code generation controls? |
* Using template languages in general is not mentioned in Code Generation in Microsoft .NET. Kathleen targets only XSLT, which is in fact a template language. But it is totally unfair to compare XSLT with “brute force” and codeDOM. That’s like explaining our modern road traffic like this: On the roads you will find trucks, busses and Porsches. And not telling that there are Ford, Mercedes, Toyota and many other cars too. By the way, I like her book very much. Kathleen has done an excellent work. I am just reading her second chapter, extracting Metadata.