Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > why is important to use : use strict?

Reply
Thread Tools

why is important to use : use strict?

 
 
Martina
Guest
Posts: n/a
 
      09-19-2005
Why is important to use "use strict"?
Perl script work very good without this command.
Am I forgot something?

Tnx.


 
Reply With Quote
 
 
 
 
Brian Wakem
Guest
Posts: n/a
 
      09-19-2005
Martina wrote:

> Why is important to use "use strict"?
> Perl script work very good without this command.
> Am I forgot something?
>
> Tnx.



There's a million reasons. It really helps with typos, that could go
unnoticed without strict.


Consider:-

my $num0 = 9;
my $num1 = 9;

my $num2 = $numO * $num1;

print "\$num2=$num2\n";


The output is '$num2=0'. It wouldn't run under strict as Global symbol
"$numO" requires explicit package name at....

Now imagine hundreds of lines, dozens of variables. Make a typo without
strict and everything still runs, but you get runtime errors. Hard to
track down. You might not even notice, but your output would be skewed.


--
Brian Wakem
Email: http://homepage.ntlworld.com/b.wakem/myemail.png
 
Reply With Quote
 
 
 
 
Jürgen Exner
Guest
Posts: n/a
 
      09-19-2005
Martina wrote:
> Why is important to use "use strict"?
> Perl script work very good without this command.
> Am I forgot something?


You are forgetting that programmers are humans, too, and thus are making
mistakes.
"use strict" catches many of those all too human mistakes like e.g. typos in
variable names.

jue


 
Reply With Quote
 
Chris Richmond - MD6-FDC ~
Guest
Posts: n/a
 
      09-19-2005
In article <mOzXe.9152$%i1.7167@trnddc09>,
"Jürgen Exner" <(E-Mail Removed)> writes:
>Martina wrote:
>> Why is important to use "use strict"?
>> Perl script work very good without this command.
>> Am I forgot something?

>
>You are forgetting that programmers are humans, too, and thus are making
>mistakes.
>"use strict" catches many of those all too human mistakes like e.g. typos in
>variable names.


I'll have to take exception to this part about variable names.
use strict; almost demands that you also use 'my' variables.
Even when using warnings too, 'my' variables aren't checked for
"variable used only once" warnings. That is my clue that I mis-type
a variable name.

I don't understand that aspect of 'my' variables.

Chris

--
Chris Richmond | I don't speak for Intel & vise versa

 
Reply With Quote
 
Sandman
Guest
Posts: n/a
 
      09-19-2005
In article <dgmb2o$9cq$(E-Mail Removed)-com.hr>, "Martina" <(E-Mail Removed)>
wrote:

> Why is important to use "use strict"?
> Perl script work very good without this command.
> Am I forgot something?
>
> Tnx.


strict catches lots of errors that aren't only critical, but could still be the
reason a huge application fails due to variables being incorrectly rrefernced
or named.

And if you make sure to always use strict (and warnings), you will find that
it's easier to get help here since you have shown that at least the syntax is
correct and thus the error must be something else.

--
Sandman[.net]
 
Reply With Quote
 
John Bokma
Guest
Posts: n/a
 
      09-19-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) (Chris Richmond - MD6-FDC ~) wrote:

> I'll have to take exception to this part about variable names.
> use strict; almost demands that you also use 'my' variables.
> Even when using warnings too, 'my' variables aren't checked for
> "variable used only once" warnings. That is my clue that I mis-type
> a variable name.


Which fails if you type a name wrong twice. Especially if you're
refactoring a project .

> I don't understand that aspect of 'my' variables.


I am sure the documentation will clear this up, a lot even.

--
John Small Perl scripts: http://johnbokma.com/perl/
Perl programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html

 
Reply With Quote
 
Jürgen Exner
Guest
Posts: n/a
 
      09-20-2005
Chris Richmond - MD6-FDC ~ wrote:
> In article <mOzXe.9152$%i1.7167@trnddc09>,
> "Jürgen Exner" <(E-Mail Removed)> writes:
>> "use strict" catches many of those all too human mistakes like e.g.
>> typos in variable names.

>
> I'll have to take exception to this part about variable names.
> use strict; almost demands that you also use 'my' variables.
> Even when using warnings too, 'my' variables aren't checked for
> "variable used only once" warnings. That is my clue that I mis-type
> a variable name.
>
> I don't understand that aspect of 'my' variables.


Trivial sample program:

my $foo = 'some text';
print $too;

Not using strictures this program just terminates without any output.

Under strictures it generates the error
Global symbol "$too" requires explicit package name at [...] line 4.
Execution of [...] aborted due to compilation errors.

Which one do you prefer?
BTW: probably you had to look two or three times to spot the mistake in the
code. A good indication that even a code review by a fellow programmer
probably would have missed this mistake.

jue


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
why why why why why Mr. SweatyFinger ASP .Net 4 12-21-2006 01:15 PM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
Why are standards important? bjg HTML 48 02-14-2004 08:52 PM
Why is variable declaration order important ? Alan Franklin Java 1 02-02-2004 12:48 PM
Re: W3C Markup Validation...if it's so important than why... William Tasso HTML 0 08-22-2003 09:47 AM



Advertisments