SPUG: Self-generating code: yea or nay? (was: Dijsktra is
dancerboy at strangelight.com
Mon Aug 12 22:20:55 CDT 2002
It sounds like all of the examples of "good" uses of self-generating
code are essentially *compilers* of some sort or other. Obviously a
compiler is going to generate code: that's what a compiler does.
That one may write a compiler *in* Perl that compiles *to* Perl may
seem a little twisted and confusing, but really it's no more twisted
than, say, all those C++ compilers out there which were mostly
written in C++.
Are there any examples of good uses of self-generating code *other*
than in compilers or interpreters?
At 1:15 PM -0700 8/12/02, Richard Anderson wrote:
>Hi Colin. Your example of Hook::LexWrap, Marc M. Adkins example and
>Geoffrey & Kristin Grosenbach's example of generating Java
>database-layer code are reasonable counter-examples, and and illustrate how
>easy Perl makes to do things that would be difficult in other languages. I
>think I'll tone down the tutorial's condemnation of self-generating code.
>However, Colin's comment about
>> ...see Lex::HookWrap. This code may take some studying (or a lecture from
>Damian ;-) to understand. Lex::HookWrap
>> autogenerates a class to unhook the hooks, when a scope is left (causing
>> an object to go out of scope, and its DESTROY method to be called).
>> What's the alternative to autogenerated code here? ;-) It's doable, but
>> with a DESTROY method that is much thicker and less intuitive.
>is indicative that self-generating code can be kind of dodgy.
>richard at richard-anderson.org
>----- Original Message -----
>From: "Colin Meyer" <cmeyer at helvella.org>
>To: "Richard Anderson" <richard at richard-anderson.org>
>Cc: "spug" <spug-list at pm.org>
>Sent: Friday, August 09, 2002 10:12 AM
>Subject: Re: SPUG: Self-generating code: yea or nay? (was: Dijsktra is Dead)
>> On Thu, Aug 08, 2002 at 10:25:35PM -0700, Richard Anderson wrote:
>> > Speaking of unstructured coding, I recently updated the online
>> > grep/map/sort tutorial and added the example below. This got me
>> > thinking: are there any cases where self-generating code is "better"
>> > (in some sense) than the alternatives? I feel the answer is no - can
> > > anyone provide a counter-example?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
POST TO: spug-list at pm.org PROBLEMS: owner-spug-list at pm.org
Subscriptions; Email to majordomo at pm.org: ACTION LIST EMAIL
Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
For daily traffic, use spug-list for LIST ; for weekly, spug-list-digest
Seattle Perl Users Group (SPUG) Home Page: http://seattleperl.org
More information about the spug-list