Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

101 reasons to use strict;

by George_Sherston (Vicar)
on Sep 29, 2001 at 01:43 UTC ( #115515=perlmeditation: print w/ replies, xml ) Need Help??

I tried strict once, it gave me a lot of prudish back chat so I deleted it again and went on my way rejoicing. After a while I began to wonder why my code was such a shambles. Then I found the monastery and got pelted with rotten fruit and had my feet held over a pot noodle until, without really knowing why, I gave in to peer pressure. Only after doing strict for a while do I begin to realise why it's such a darned good thing.

Now I think a of immediate practical benefits one gets from use strict would be a nice thing to have: we could refer agnostics and atheists to it, to bring them to the light more speedily.

Reason 1
If you often get hash values out of hash references (for example if you use DBI to get items from your databases) you may sometimes forget your syntactical sugar. Under strict you get an error if you write $ref{LineID} instead of $ref->{LineID} (unless you already declared an array called %ref which is most unlikely, not to say unwise). But without strict you might very well plonk the "value" back into another DBI query, and end up pulling out line 0 from your database without knowing that was what you were doing.

Over to you, siblings...

George Sherston

Comment on 101 reasons to use strict;
Select or Download Code
Re: 101 reasons to use strict;
by runrig (Abbot) on Sep 29, 2001 at 01:57 UTC
    Reason 2

    You might be writing an e-commerce app, and have a routine that goes something like this:

    sub accept_order { ($order_id, $credit_card_nbr, $payment_amount) = @_; save_order_in_database($ord_id, $pymt_amount); charge_credit_card($credit_card_no, $payment_amt); }
(tye)Re: 101 reasons to use strict;
by tye (Cardinal) on Sep 29, 2001 at 04:22 UTC

    Not 101 reasons, but strict.pm tries to explain "why".

            - tye (but my friends call me "Tye")
      It's a very tip top explanation for someone who already believes... I was thinking a bit of propaganda for the person who reads it and thinks "yeah yeah, but what's in it for me?" - some actual pratfalls that happen[|ed] to actual people who didn't use strict. My suspicion of strict was that it was for perfectionists, people who didn't work by the 80:20 rule. I had to make a shed load of mistakes to realise it was the exact opposite, some of which might be worth documenting as cautionary tales.

      George Sherston
Re: 101 reasons to use strict;
by jepri (Parson) on Sep 29, 2001 at 20:00 UTC
    I always wonder where people who don't use strict learned to program. Most (fully) compiled languages are much more harsh than 'strict' in Perl - you must predeclare *everything*, and you can never be ambiguous.

    I freely confess that the thing that kept away from strict the most was the 'my' command - I didn't understand what it did. I kept searching through the docs trying to find out how to declare an 'int' or a 'string'. I can laugh about it now...

    I previously wrote medium size programs in basic and found that after a few thousand lines the program fell apart - my best techniques couldn't cover up for my mistakes. I really appreciate strict. It's like having someone sitting behind me saying things like "you misspelt that".

    I even get annoyed at it for things like not telling me when my variable goes out of scope and I get the wrong value because of the parent scope. Do what I mean!

    ____________________
    Jeremy
    I didn't believe in evil until I dated it.

Re: 101 reasons to use strict;
by hsmyers (Canon) on Sep 29, 2001 at 21:19 UTC
    As I remember it, there was a time when many 'real' programmers couldn't understand this thing called function prototyping in 'C'.

      I carefully avoided invoking the name of the language that I hope I will never be forced to learn.

      There are plenty of others with nasty compilers out there.

      ____________________
      Jeremy
      I didn't believe in evil until I dated it.

Re: 101 reasons to use strict;
by Brovnik (Hermit) on Sep 30, 2001 at 02:50 UTC
    Because if you don't use it, it might get taken away and then we'd be back to the bad old days (e.g. Perl 4) when you had to do your own debugging, rather than have Perl do it for you !
    --
    Brovnik
Re: 101 reasons to use strict;
by dragonchild (Archbishop) on Oct 01, 2001 at 16:50 UTC
    1. If you don't use strict, we won't want to help you.
    2. If you still don't use strict, we will NOT help you.
    3. It will catch mispelled variable names.
    4. It will catch missing '$', '@', '%', and '&'.
    5. It will force you to actually know what variables you're using.
    6. It will not let you use local unless you specifically say you want to. (Instead, you have to use our to scope globals.)
    7. It will prevent variable-clobbering due to scope changes. (You still shouldn't use the same variable name in different scopes, but this helps even if you're silly.)
    8. It will help you program better.
    9. It elevates Perl from the level of shell-scripting to the level of a true application.
    10. It makes maintenance of Perl applications possible. (I'm not exaggerating about this one.)
    11. And, the most important reason is "Because I said so."

    ------
    We are the carpenters and bricklayers of the Information Age.

    Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

Re: 101 reasons to use strict;
by George_Sherston (Vicar) on Oct 02, 2001 at 04:46 UTC
Re: 101 reasons to use strict;
by soniamdisappoint (Initiate) on Jun 02, 2011 at 23:48 UTC
    Hate to be the simpleton, but basically it just enforces good practice and generates far more readable code. And everybody hates people who don't.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://115515]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (8)
As of 2014-11-28 18:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (199 votes), past polls