On Wed, Feb 16, 2011 at 4:33 PM, Stefan Weiss <[email protected]> wrote:

> This is called "autovivification" in Perl-speak, and it's intended to
> make life easier by reducing the amount of typing (same thing we're
> talking about here). Unfortunately, it will also do this if you just try
> to read a value:
>

*That* was it!  I knew Perl had a term for this.


>  my $bar = {};
>  if ($bar->{hey}{ho}{lets}{go}) ...
>
> - and bam!, $bar is now -
>
>  {
>    'hey' => {
>      'ho' => {
>        'lets' => {}
>      }
>    }
>  };
>
>
IMHO, this behavior might make things easier when you're going to assign
> values, but on the flip side, it can and often will create unnecessary
> objects (hashes) when you only wanted to read a value. This can easily
> happen in situations where a module maps a tree (like XML) to a hash of
> hashes, or similar structures.
>

Just because Perl is broken doesn't mean Javascript has to be :)  Why not a
constraint that says "don't create objects unless there's an assignment"?  I
mean, once you know that something at depth n is undefined, you know that
everything at depth n+m is undefined as well, right?

PS. I still love Perl, weird as it is :)
>
>
Evil!  Outcast unclean!  :)

_jason

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/[email protected]/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/[email protected]/

To unsubscribe from this group, send email to
[email protected]

Reply via email to