Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^3: Best practices, revisited

by Jenda (Abbot)
on Jul 06, 2009 at 01:52 UTC ( [id://777421]=note: print w/replies, xml ) Need Help??


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

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.

Jenda
Enoch was right!
Enjoy the last years of Rome.

Replies are listed 'Best First'.
Re^4: Best practices, revisited
by ysth (Canon) on Jul 06, 2009 at 08:57 UTC
    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.

Log In?
Username:
Password:

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

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

    No recent polls found