Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

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

by Xiong (Hermit)
on Feb 25, 2012 at 14:36 UTC ( [id://956120]=note: print w/replies, xml ) Need Help??


in reply to Re^7: RFC: Tutorial: use strict; now what!?
in thread RFC: Tutorial: use strict; now what!?

Being an obedient student, I always use warnings as well as strict...
The plot thickens...

Sorry, tangent; neither strictures nor warnings are always appropriate. That's why they can be turned off -- in fact, they're off by default. Much power is hidden away by each. Usually you don't want, or need, to do such stuff. Sometimes you do.

Also, no tool can guarantee that your code is bug-free or even typo-free. Some tools help to protect against some common mistakes but in the end, it's up to you. The most important abilities required to write less-buggy programs are (obliquely to Wall's dicta) humility, intellectual honesty, clean and consistent style, flexible focus, and raw experience.

I would not recommend that you check every hash key for existence before each use. But if you want to do something like this, you can try Hash::Util or (if you tend to work with $hashrefs rather than actual %hashes) Data::Lock. Please note that these are not equivalent tools.

Please don't take away from any comment here, especially from any comment of mine, that you must always or must never do anything. Software should be judged (in this order) by: (1) how well it works for the user, (2) how well it serves the needs of those who incorporate it as a component of other projects, and (3) how well it can be maintained, extended, and upgraded in future. Not on the list: impressing CS profs and didactic engineers busy evading their own work while prescribing your style.

I'm not the guy you kill, I'm the guy you buy. —Michael Clayton

Replies are listed 'Best First'.
Re^9: RFC: Tutorial: use strict; now what!?
by chromatic (Archbishop) on Feb 25, 2012 at 22:02 UTC
    ... in fact, they're off by default.

    That's no argument against either one. (I agree that some of the default warnings are questionable, but that's a different discussion.) Plenty of things have the wrong defaults: Unix crypt, C's string handling, Perl 5 optimizing its defaults for awk-replacement one-liners instead of programs, and more.

      I hope nothing I've written can be taken as an argument against strictures or warnings. I merely place them in the proper light: as tools, not magic shields.

      I'm not the guy you kill, I'm the guy you buy. —Michael Clayton
Re^9: RFC: Tutorial: use strict; now what!?
by tangent (Parson) on Feb 25, 2012 at 16:12 UTC
    Hi Xiong, thanks again. I was being a bit tongue in cheek when I said about "being an obedient student", though I do always use warnings in development and find it invaluable. runrig's comment showed me that by writing code just to have it comply with warnings could actually introduce more subtle errors. Taking from this, I have written a little test script to find these errors rather than weigh down my code.
    The most important abilities required to write less-buggy programs are (obliquely to Wall's dicta) humility, intellectual honesty...
    My reading of Larry suggests you have to follow your virtuous path in order to reach his. For example, I have learned to change my attitude to dealing with mistakes in my design or code (aka: error reports). Users are really quick at finding errors and unforeseen traps. Instead of being protective and defensive (hubris?), or blaming Internet Explorer, I will happily describe exactly how I've erred. Then, if I fix things quickly, I find the user has more faith in both me and the code. After many such iterations, finally I'm allowed some pride.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://956120]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2024-04-23 20:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found