Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

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

by tangent (Priest)
on Feb 17, 2012 at 19:16 UTC ( #954595=note: print w/replies, xml ) Need Help??

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

I kinda knew there would be something. And "if ($hash{pensionbalance})" is exactly the sort of thing I would put in to avoid all those "uninitialized value" errors. The plot thickens... I could change those conditions to:
if (exists $hash{pensionbalance}) { print "It's there, there's just nothing in it\n" }

Replies are listed 'Best First'.
Re^8: RFC: Tutorial: use strict; now what!?
by Xiong (Hermit) on Feb 25, 2012 at 14:36 UTC
    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
      ... 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
      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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://954595]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (6)
As of 2017-10-21 09:14 GMT
Find Nodes?
    Voting Booth?
    My fridge is mostly full of:

    Results (269 votes). Check out past polls.