[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: last dynamically scoped()? (was Re: [FWP] awww, no fun :()



I'm CCing this to p5p because the same discussion is going on there.


On Thu, Apr 12, 2001 at 11:27:31PM +0200, Abigail wrote:
> > Essentially, consider the following...
> > 
> >         while(1) {
> >             foo();
> >         }
> > 
> > When will that exit normally (ie. not via a die or exit)?  This should
> > be a simple answer, but you can't know without examining foo() and all
> > routines foo() might call.  This is bad.
> 
> Ah, so I guess we should deprecate 
> 
>     while ($i) {
>         foo();
>     }
> 
> as well, because you don't know when that exits without examing foo.

How did I know you were going to come back with something like this?
As soon as I sent the mail, I thought "Abigail will try to argue this
ad absurdum".


I'm not saying I want to solve the halting problem!  But last's
behavior makes it grossly unpredictable.  With...

        while($i) { foo(); }

I know what the conditional is.  Its $i!  If $i is lexical, then the
scope of code that can control the loop is limited.  If $i is global
its a wider problem, but its MY PROBLEM and MY CHOICE (where 'me' is
the author of the looping code) because *I* chose the loop conditions.
Not the choice of the subroutine I called.  And its immediately
obvious from the code what lines of investigation I should persue in
determining the control flow of the loop.


More to the point, why have this complication?  What good is it?  What
does it do that's really useful enough to justify screwing with
control flow so badly?


I've got a bug up my ass about this because I've been doing alot of
code archeology and large-scale refactorings on live systems lately.
Sitting down and figuring out what all the possible side effects of a
piece of code are, and all the possible ways it might be (ab)used is
NOT EASY.

I've identified a few red flags in this (rgrep is a wonderful
refactoring tool) that just throw predictability out the window.
AUTOLOAD, goto, symbolic references, dynamic method calls
(ie. $obj->$name()), not using strict, 'no strict', fully-qualified
names, etc...  Fortunately these are all relatively rare, so if I see
one I know something funny is going on and can investigate.

last/redo/next are not rare at all, and have perfectly innocent uses.
Even though they can be used for nasty side-effects, I can't usefully
scan for them without sucking down an unreasonable amount of my time.
And the run-time warning is of no use to me because its probably in
code that's a rare condition and not triggered by a test (and
unfortunately, I usually have to write the tests.)  And if anyone
thinks its possible to have tests with 100% coverage over 140,000
lines of code (the current system I'm working on) tell the Easter
Bunny he still owes me twenty bucks.


-- 

Michael G. Schwern   <schwern@pobox.com>    http://www.pobox.com/~schwern/
Perl6 Quality Assurance     <perl-qa@perl.org>	     Kwalitee Is Job One
<Skrewtape> I've heard that semen tastes different depending on diet.  Is that
	    true?
<Skrewtape> Hello?
<Schwern> Skrewtape:  Hang on, I'm conducting research.

==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe