NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.
All the Perl that's Practical to Extract and Report
Stories, comments, journals, and other submissions on use Perl; are Copyright 1998-2006, their respective owners.
copy and paste (Score:1)
Code generation is OK if it's transient -- passed straight to a compiler and run. If instead it's written to disk as a template, then it's just formalized copy-and-paste, with all of the maintenance downsides.
The biggest drawback to runtime code generation is obscurity. It's opaque to static analysis and smat editors, and to most humans too.
Re: (Score:1)
The biggest drawback to runtime code generation is obscurity. It's opaque to static analysis and smat editors, and to most humans too.
Indeed. A static analyzer would have to be really smart to figure out that I'm collecting together little pieces of code as I traverse the AST...
Oh, and there seems to be another cardinal law involved in code generation: whatever happens, don't ever expect both your programs to look nicely indented anymore.
Re: (Score:1)
In the worst case, you can use templates for the generated code. That pulls the odd indentation out of the main code.
Re:copy and paste (Score:1)
I might give it a try. It does solve the templating issue, but it introduces distance between the templates and the place(s) where they're used. It's a bit of a lesser-of-two evils situation.
Reply to This
Parent
Re: (Score:1)
True. Java is actually lucky in this area: it's trivial to embed an arbitrary file in a Jar file right next to the .class that uses it.