Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Why does exists cause autovivication?

by Anonymous Monk
on Dec 29, 2007 at 04:16 UTC ( #659440=note: print w/ replies, xml ) Need Help??


in reply to Why does exists cause autovivication?

Quite logic to me... becuase you peeked.

Big picture...Autovivification is one of the worst bugged feature in perl. Let the language to guess the programmer's mind is never a good thing. To initialize a hash element is never and will ever be a big deal in any normal mind, thus there was never a need to be that much lazy - perl seemed to help when in fact to demage.


Comment on Re: Why does exists cause autovivication?
Re^2: Why does exists cause autovivication?
by demerphq (Chancellor) on Dec 29, 2007 at 14:17 UTC

    Oh how ye discredit thyself! Auto-viv is much more useful than you make it sound and it only rarely causes problems, usually because someone hasn't managed to understand how it works.

    ---
    $world=~s/war/peace/g

      Thy careless writing, brother, doth bring pain unto mine eyes, for verily thou mixest the high and low modes of address, like unto a novice that mistaketh his sigils, as "@foo[0]" &c. Wherefore I commend unto thee that when thou wouldst chastise thy brethren so, thou shouldst say instead "How thou discreditest thyself", or "how ye discredit yourself".

      I think I agree with your point, though. Autovivification is one of those features that's both a strength and a weakness of Perl. A strength, because it's a very practical feature that makes life a bit easier for you and me; a weakness, because people who suffer from a surfeit of the wrong sort of laziness use it as an example of how Perl is "too hard".

        Whoops! :-) Thanks for the correction. (And ++ for style :-)

        ---
        $world=~s/war/peace/g

Re^2: Why does exists cause autovivication?
by Jenda (Abbot) on Dec 29, 2007 at 14:48 UTC

    Let me see ... how many times have I spent time hunting a bug caused by autovivification during my ten years with Perl ... zero. How many times did it save me from code like if($data and $data->{foo} and $data->{foo}{bar} and $data->{foo}{bar}{baz} and $data->{foo}{bar}{baz}{bat}) or

    if (!exists($data->{$key}) { $data->{$key} = []; } push @{$data->{$key}}, $new_value;
    ? Countless.

    If you hear about autovivification for the first time it may sound scary, but you do get used to it. And the problems caused by autovivification are few and far apart.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (7)
As of 2014-09-24 01:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (244 votes), past polls