Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re^5: On Commenting Out 'use strict;'

by Limbic~Region (Chancellor)
on Aug 11, 2005 at 14:02 UTC ( #482960=note: print w/replies, xml ) Need Help??

in reply to Re^4: On Commenting Out 'use strict;'
in thread On Commenting Out 'use strict;'

Ok, I am a big advocator of using the strict and warnings pragmas as well as the diagnostics when necessary. With that said, how does a novice distinguish between a warning an error. Consider the following 1 liner
perl -e "my $foo; my $bar = 3; $bar += $foo; print $bar" versus perl -Mwarnings -e "my $foo; my $bar = 3; $bar += $foo; print $bar"
Perl's DWYMery silently converts undef to 0 for us without warnings producing the correct answer in both cases but with warnings it warns me of a potential problem. In fact, Perl isn't consistent in its warnings:
# ++ is a short cut for $foo = $foo + 1 perl -Mwarnings -e "my $foo; $foo++; print $foo"

Cheers - L~R

Replies are listed 'Best First'.
Re^6: On Commenting Out 'use strict;'
by bofh_of_oz (Hermit) on Aug 11, 2005 at 14:08 UTC
    Somehow, I believe you've answered your own question. If you do not turn the warnings on, you do not get warnings to show up. What I usually do is enable "use strict", make the script compile and produce the results I expect (therefore, ensuring the errors are dealt with), then turn on "use warnings" and polish the script until all the warnings are gone. It's like "deal with the prolems first; make it nicer later"...

    An idea is not responsible for the people who believe in it...

      Somehow, I believe you've answered your own question.

      No I didn't, you did. Your answer is that the novice can distinguish errors from warnings by using strict only first. After getting it to compile and produce the correct results, they can add in warnings to polish it off.

      Why does one need to fix any of the so called errors if the code produces the correct results? The strict pragma really doesn't do much other than force you to declare your variables and not use them as symbolic references. Neither of those things absolutely means error as both can be ignored and still produce the correct results. Why then are they errors in your opinion that must be fixed?

      My point is not to say it is ok to write code that isn't compliant with strict and warnings. My point is that for the initiate in the language, learning the why the warning or error is being spewed forth is much more important then making it go away. This takes time and effort. Not all messages from strictures need to "fixed" as you say. I have intentionally used symbolic refs to manipulate the symbol table. Fortunately for us, both pragmas are lexical and can be turned off when the message doesn't fit the crime. Understanding the why behind the message lets us know when it is ok to do that.

      Cheers - L~R

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://482960]
[Corion]: Meh. I need to find myself a better "programming" feed than r/programming (which is just HackerNews reposts and advertisements, very little code). Maybe I should select a list of links that I liked on r/programming and then google for ...
[Corion]: ... an aggregator site that also listed (ideally) all of these links once. And maybe also have an exclude list to blacklist some of the most spammy links that the site may have never mentioned at all
[marto]: I gave up reading HN at all, and feel much better for it :P
[Corion]: Now, how to best automate that Google search ... :-)
[Corion]: marto: Yeah, I'm also short of not reading it at all. I already stopped reading it in the morning because it gave me a foul mood.
[Corion]: The good posts on HN are the non-computing posts. Most of the other stuff is maybe relevant to you if you are 20 and live in Silicon Valley...
[Corion]: Two attributes that don't describe me.
[Corion]: Maybe I should also write a curator for HN or simply not read it anymore, like you do.

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (8)
As of 2017-07-24 13:24 GMT
Find Nodes?
    Voting Booth?
    I came, I saw, I ...

    Results (354 votes). Check out past polls.