Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: RFC: Tutorial: use strict; now what!?

by educated_foo (Vicar)
on Feb 08, 2012 at 13:39 UTC ( #952495=note: print w/replies, xml ) Need Help??


in reply to RFC: Tutorial: use strict; now what!?

No lecture on strict is complete without MJD's summary of what it does:
  1. It enables strict 'refs', which prevents strings from being accidentally used as references. None of the examples in the book used references at all, so there was no reason to use strict 'refs'.
  2. It enables strict 'vars', which prevents global variables from being used without being declared; typically, one declares variables local with the my declaration. While this is good practice in general, the example programs were all very small---less than twenty lines each. In such small programs, there is no practical difference between a global variable and one that has been declared with my. No benefit would have accrued from requiring the use of my declarations of every variable.
  3. It enables strict 'subs', which is of very limited value even at the best of times. strict 'subs' forbids unquoted strings, because such strings ('barewords') can cause long-term maintenance problems. If you have code like
  4. if ($x eq carrots) { ... }

    the carrots is taken as a literal string. But if someone later adds a carrots() function to the program, the meaning of this line might change suddenly and unexpectedly, to call carrots() and compare $x with the returned value. This is not too likely, except perhaps in very large and long-lived programs, which is why strict 'subs' is of such limited value. In 20-line book examples, it is of no value whatsoever.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://952495]
help
Chatterbox?
[stevieb]: did my pull request challenge today, Locale::gettext. Weird layout for a dist, and I have no idea how to use it, but it's always nice when you can force someone else's work be use strict; and use warnings; compliant :)
[stevieb]: ahem... s/no idea how to use it/didn't read enough as to what it's used for/
[stevieb]: interestingly enough, someone else got my Devel::Examine:: Subs distribution for their PRC, and I applaud the change. This dist is extremely complicated and mostly obfu, but the person doing it understood PPI enough to change...
[stevieb]: ...something I had overlooked in the extreme depths of the core functionality. After merging, then a couple of extra tweaks, I still have 100% test coverage. Yay for people who write tests!

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2017-01-24 01:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you watch meteor showers?




    Results (199 votes). Check out past polls.