Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re: Code Generation with Perl?

by perrin (Chancellor)
on Oct 03, 2003 at 23:48 UTC ( #296434=note: print w/replies, xml ) Need Help??

in reply to Code Generation with Perl?

The book Advanced Perl Programming has a whole chapter on this, and there is also this article on However, code generation (at least when it involves actual files, as opposed to just AUTOLOAD and eval magic) often indicates that you're doing something wrong. This has been widely discussed under the term "code smell." The gist of it is that your language should be able to factor out repetitive tasks without needing to actually generate code to do it. Also, code generation systems often lead to bad situations where people edit the generated code by hand and then can't generate it again without losing that work. So, use with caution.

Replies are listed 'Best First'.
I couldn't agree more
by cbraga (Pilgrim) on Oct 04, 2003 at 00:13 UTC
    My take is that code generation is a necessity when you need to express concepts difficult for a language. Case in point, compilers generated in C with yacc/bison. While we certainly could write those by hand in C, generating code is much more productive because we can work in a level of abstraction impossible in the target language without sacrificing C's efficiency.

    Not the case with Perl, though. Perl is at a much higher level than C and I've yet to see a case where we actually need to generate Perl code due to the difficulty of writing it directly in the first place. The cases I've seen do it for performance. Even Autoload, while convenient, could be done away with without losing much, I think.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://296434]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2018-05-25 19:28 GMT
Find Nodes?
    Voting Booth?