At 11:18 AM 7/12/02 -0500, David T-G wrote:
>Peter, et al --
>
>...and then Peter Scott said...
>%
>...
>% code.  (Yes, IMHO, if you insist.)  My students see it in every program
>% I show them, from Hello World onward.  I tell them that if anyone gives
>% them code without it to maintain, they should refuse if at all
>% possible.  Later on I show the beginners a nasty example of the
>% consequences of leaving out use strict, -w/use warnings, or both.
>
>Oooh!  Oooh!  Show me an example or two!  Please?  Sounds great!
>
>Simple, concise examples are great convincers.

Well, I actually use it to illustrate scoping, but then I show what 
happens with the -w and strict removed; anyway, here you are:

#!/usr/bin/perl -w
use strict;
my $x = "global";
my $y = "also global";
{
   my $x = "local";
   my $z = "also local";
   can_I_see_z();
   print "$x, $y\n";
}

sub can_I_see_z {
   my $y = "trashed???";
   print $z;
}

With strict/-w it does not run.  With -w it warns but runs.  With 
neither it runs without any indication that it cannot possibly be doing 
what the author probably intended, and yet the author clearly has a 
fundamental misunderstanding about the nature of scoping.  Then I 
suggest to them that all those strict/-w - less scripts they've 
encountered probably have all kinds of problems like this within them.

An even more killer example of this would be very handy.

One of the best testimonials I got (probably on this issue) was 
second-hand: someone was relating how a mutual colleague was creating a 
program and said, "This isn't how Peter would do it, but it saves 
time."  It didn't work.  So then they asked deferentially, "So... how 
would Peter do it?"  He changed the program and it worked.  Anecdotes 
like that make this job so worthwhile :-)

--
Peter Scott
Pacific Systems Design Technologies
http://www.perldebugged.com/


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to