Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re^2: Best practices, revisited

by ysth (Canon)
on Jul 05, 2009 at 19:25 UTC ( #777383=note: print w/replies, xml ) Need Help??

in reply to Re: Best practices, revisited
in thread Best practices, revisited

For instance I'm a terrible typist (as all who read my CB-postings will readily agree), so I wouldn't think of writing even small scripts without "use strict;. On the other hand I rarely if ever "use warnings;"
I'd think you'd love the uninitialized warning, then. Maybe you never use constant hash keys?

Replies are listed 'Best First'.
Re^3: Best practices, revisited
by Jenda (Abbot) on Jul 06, 2009 at 01:52 UTC

    Or maybe not. Undef is too often a valid value or an expected return value. A warning for the read access to a nonexistent hash key might make sense. And would point to the line of the possible typo. Warning about the use of an undef, even if called "uninitialized value", is mostly pointless. It forces you to write more code and more code means more bugs and it often points to a wrong place in the code.

    If you are afraid of mistyping the hash key, lock the hash via Hash::Util.

    Enoch was right!
    Enjoy the last years of Rome.

      undef silently becoming "" or 0 is definitely attractive, but to me far from worth going without warnings. I don't find the uninitialized warning at all pointless; it almost always indicates a bug (sometimes a typo, but sometimes a logic error.) The extra work to avoid the warning in correct code is trivial and hard for me to get wrong.
Re^3: Best practices, revisited
by CountZero (Bishop) on Jul 05, 2009 at 19:34 UTC
    For some strange reason I seem not to have a problem with hash-keys. They get rarely mistyped.


    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2018-04-26 17:53 GMT
Find Nodes?
    Voting Booth?