[24097] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 6291 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Mar 22 14:10:35 2004

Date: Mon, 22 Mar 2004 11:10:08 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Mon, 22 Mar 2004     Volume: 10 Number: 6291

Today's topics:
    Re: working example File::Taill (GreenLight)
    Re: working example File::Taill <uri@stemsystems.com>
    Re: working example File::Taill (Anno Siegel)
    Re: working example File::Taill <Me@myco.com>
    Re: working example File::Taill <uri@stemsystems.com>
    Re: working example File::Taill (Anno Siegel)
    Re: working example File::Taill <Me@myco.com>
    Re: working example File::Taill <uri@stemsystems.com>
    Re: working example File::Taill ctcgag@hotmail.com
    Re: working example File::Taill <tassilo.parseval@rwth-aachen.de>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: 22 Mar 2004 06:05:55 -0800
From: google@milbaugh.com (GreenLight)
Subject: Re: working example File::Taill
Message-Id: <c4b60ce1.0403220605.585476d7@posting.google.com>

Richard Morse <remorse@partners.org> wrote in message news:<remorse-D994B9.15232619032004@plato.harvard.edu>...
> It's better not to pre-declare your variables -- declare them just where 
> you'd need them...
> 
> Ricky

Just in case there are some impressionable young newbies out there 8^)
this bit of "advice" is quite poor -- in fact, using "strict" and
pre-declaring your variables is very good programming practice.

--
my real address is perl - at - milbaugh - dot - com


------------------------------

Date: Mon, 22 Mar 2004 14:18:02 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: working example File::Taill
Message-Id: <x7u10h55k5.fsf@mail.sysarch.com>

>>>>> "G" == GreenLight  <google@milbaugh.com> writes:

  G> Richard Morse <remorse@partners.org> wrote in message news:<remorse-D994B9.15232619032004@plato.harvard.edu>...
  >> It's better not to pre-declare your variables -- declare them just where 
  >> you'd need them...
  >> 
  >> Ricky

  G> Just in case there are some impressionable young newbies out there 8^)
  G> this bit of "advice" is quite poor -- in fact, using "strict" and
  G> pre-declaring your variables is very good programming practice.

that is not what he said. he said don't declare them before you use
them. this means declaring them in the tightest scope possible and just
when you first use the variable. the difference is this:

your way:

my $foo ;
my bar ;


$bar = ...
while( ... ) {

	$foo = ....
}


the better way:

my $bar = ....
while( ... ) {

	my $foo = ....
}


you save lines of code, the declaration is near or at the first use, and
variables are scoped as tightly as possible.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


------------------------------

Date: 22 Mar 2004 14:22:11 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: working example File::Taill
Message-Id: <c3msqj$m6i$1@mamenchi.zrz.TU-Berlin.DE>

GreenLight <google@milbaugh.com> wrote in comp.lang.perl.misc:
> Richard Morse <remorse@partners.org> wrote in message
> news:<remorse-D994B9.15232619032004@plato.harvard.edu>...
> > It's better not to pre-declare your variables -- declare them just where 
> > you'd need them...
> > 
> > Ricky
> 
> Just in case there are some impressionable young newbies out there 8^)
> this bit of "advice" is quite poor

Not if you read it right.

>                                     -- in fact, using "strict" and
> pre-declaring your variables is very good programming practice.

The suggestion wasn't against declaration, it was against *pre*declaration.
In other words, don't declare your variables in a block at the head
of the program, but do it when you first need them.

Anno


------------------------------

Date: Mon, 22 Mar 2004 20:03:50 +0530
From: Abhinav <Me@myco.com>
Subject: Re: working example File::Taill
Message-Id: <IVC7c.16$d11.134@news.oracle.com>

Hi ..

Uri Guttman wrote:
>>>>>>"G" == GreenLight  <google@milbaugh.com> writes:
> 
> 
>   [SNIPped by Abhinav]
>   >> 
>   >> Ricky
> 
>   G> Just in case there are some impressionable young newbies out there 8^)
>   G> this bit of "advice" is quite poor -- in fact, using "strict" and
>   G> pre-declaring your variables is very good programming practice.
> 
> that is not what he said. he said don't declare them before you use
> them. this means declaring them in the tightest scope possible and just
> when you first use the variable. the difference is this:
> 
> your way:
> 
>  [SNIPPed by abhinav]
> 
> you save lines of code, the declaration is near or at the first use, and
> variables are scoped as tightly as possible.

Couldnt this be a disadvantage in big projects, where declaring criables 
at the top of the appropriate scope allows ppl to find *all* the 
variabled in that *unit* in a single place, rather than strewn all 
across .. ?

I understand this is a matter of style ..but still .. any inputs/comments ?
> 
> uri
> 

Regards
Abhinav

---

"Where there is a will, there is a way"
Replace Me with abhinavmodi, myco with yahoo .. and you have my id !



------------------------------

Date: Mon, 22 Mar 2004 14:34:36 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: working example File::Taill
Message-Id: <x7r7vl54sj.fsf@mail.sysarch.com>

>>>>> "A" == Abhinav  <Me@myco.com> writes:

  A> Couldnt this be a disadvantage in big projects, where declaring
  A> criables at the top of the appropriate scope allows ppl to find *all*
  A> the variabled in that *unit* in a single place, rather than strewn all
  A> across .. ?

why would you want to see all the variables in one place? they are out
of context and many are in the wrong scope. use scoping at the primary
reason not to do this. then simplicity of code as the second.

how about this reason i just saw recently? i rewrote a module that had
all the variables declared at the top. and i found some that weren't
used any more. if they had been delcare when first used and then deleted
you wouldn't have that problem.

  A> I understand this is a matter of style ..but still .. any inputs/comments ?

it is style sure, but the strong consensus is that it is poor style.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


------------------------------

Date: 22 Mar 2004 14:42:16 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: working example File::Taill
Message-Id: <c3mu08$m6i$2@mamenchi.zrz.TU-Berlin.DE>

Abhinav  <Me@myco.com> wrote in comp.lang.perl.misc:
> Hi ..
> 
> Uri Guttman wrote:
> >>>>>>"G" == GreenLight  <google@milbaugh.com> writes:
> > 
> > 
> >   [SNIPped by Abhinav]
> >   >> 
> >   >> Ricky
> > 
> >   G> Just in case there are some impressionable young newbies out there 8^)
> >   G> this bit of "advice" is quite poor -- in fact, using "strict" and
> >   G> pre-declaring your variables is very good programming practice.
> > 
> > that is not what he said. he said don't declare them before you use
> > them. this means declaring them in the tightest scope possible and just
> > when you first use the variable. the difference is this:
> > 
> > your way:
> > 
> >  [SNIPPed by abhinav]
> > 
> > you save lines of code, the declaration is near or at the first use, and
> > variables are scoped as tightly as possible.
> 
> Couldnt this be a disadvantage in big projects, where declaring criables 
> at the top of the appropriate scope allows ppl to find *all* the 
> variabled in that *unit* in a single place, rather than strewn all 
> across .. ?

The idea of declaring variables locally is that there *are* no (or
very few) variables that are valid throughout the unit, whatever that
is.  Instead, variables have small scopes, like the body of a loop,
and they are declared right there.

Anno


------------------------------

Date: Mon, 22 Mar 2004 20:16:03 +0530
From: Abhinav <Me@myco.com>
Subject: Re: working example File::Taill
Message-Id: <95D7c.17$d11.61@news.oracle.com>



Uri Guttman wrote:

>>>>>>"A" == Abhinav  <Me@myco.com> writes:
> 
> 
>   A> Couldnt this be a disadvantage in big projects, where declaring
>   A> criables at the top of the appropriate scope allows ppl to find *all*
>   A> the variabled in that *unit* in a single place, rather than strewn all
>   A> across .. ?
> 
> why would you want to see all the variables in one place? they are out
> of context and many are in the wrong scope. use scoping at the primary
> reason not to do this. then simplicity of code as the second.
> 
> how about this reason i just saw recently? i rewrote a module that had
> all the variables declared at the top. and i found some that weren't
> used any more. if they had been delcare when first used and then deleted
> you wouldn't have that problem.
> 
How about this ?

 > the better way: (Your)

 > my $bar = ....
 > while( ... ) {
 >
 >	my $foo = ....
 > }

 > you save lines


my way (for better or for worse?? )

my $bar;
 ...
 ..
$bar = ....
 ...

while(...){   #Another Scope ...
  my $foo;     # if the while loop is short, we could use m4 $foo = ...
  ....
  $foo = ...
}

[SNIP]
> 
> uri
> 

Regards
Abhinav



------------------------------

Date: Mon, 22 Mar 2004 15:12:30 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: working example File::Taill
Message-Id: <x7n0686hlu.fsf@mail.sysarch.com>

>>>>> "A" == Abhinav  <Me@myco.com> writes:

  A> Uri Guttman wrote:

  A> my way (for better or for worse?? )

  A> my $bar;
  A> ...
  A> ..
  A> $bar = ....
  A> ...

why waste the extra lines of code? there is no gain to your style AFAIK.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


------------------------------

Date: 22 Mar 2004 17:03:27 GMT
From: ctcgag@hotmail.com
Subject: Re: working example File::Taill
Message-Id: <20040322120327.272$KG@newsreader.com>

Abhinav <Me@myco.com> wrote:
> Uri Guttman wrote:
> >
> > you save lines of code, the declaration is near or at the first use,
> > and variables are scoped as tightly as possible.
>
> Couldnt this be a disadvantage in big projects, where declaring criables
> at the top of the appropriate scope allows ppl to find *all* the
> variabled in that *unit* in a single place, rather than strewn all
> across .. ?

Why would I want to find all the variables in that unit in a single place?

If I wanted that, wouldn't grep 'my' work just fine?

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


------------------------------

Date: 22 Mar 2004 18:51:37 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: working example File::Taill
Message-Id: <c3ncjp$gkm$1@nets3.rz.RWTH-Aachen.DE>

Also sprach ctcgag@hotmail.com:

> Abhinav <Me@myco.com> wrote:
>> Uri Guttman wrote:
>> >
>> > you save lines of code, the declaration is near or at the first use,
>> > and variables are scoped as tightly as possible.
>>
>> Couldnt this be a disadvantage in big projects, where declaring criables
>> at the top of the appropriate scope allows ppl to find *all* the
>> variabled in that *unit* in a single place, rather than strewn all
>> across .. ?
> 
> Why would I want to find all the variables in that unit in a single place?

This relates to the concept of "locality" in programming (as described,
for instance, in Gerald M. Weinberg's "The psychology of computer
programming"). Even the issue of where to declare variables is
explicitely mentioned:

    "Yet even when the language requires all declarations to be given in
     one place, a certain locality is obtained, for we can always tear
     off the first page and keep it alongside whichever page we are
     currently using." [p.230, Silver anniversary ed.]

> If I wanted that, wouldn't grep 'my' work just fine?

No, it wouldn't, because you'd be jumping around through the source and
leaving the part of the program that you initially wanted to inspect.

I tend to regard my programs as a sequence of logical blocks (not blocks
in the sense of { }). I mark them with a preliminary comment or maybe an
additional empty line preceding them. I then often declare all the
variables introduced in this block at the top of it. That means for a
function I don't declare all my variables at the top of it. But I don't
declare them right when I introduce them, either. It's somewhere in
between.

Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 6291
***************************************


home help back first fref pref prev next nref lref last post