in reply to Re: Re: RFC - inplace upgrade for Tie::SortHash
in thread RFC - inplace upgrade for Tie::SortHash

Today I decided to start over. I would like to address the points you made on the previous code:

Hmm, im not up for responding completely yet, so you can expect a /msg that this reply has been updated. However, there is one point id like to address:

The code is correct as written. ...

defined $self->[ARRAY][$index] ? $self->[ARRAY][$index] : undef;

Except that its misleading as hell. It is _exactly_ equivelent to

$self->[ARRAY][$index]

Except that it makes a reader wonder what magic specialness is going on, and is marginally slower. If nothing special is happening then it should be changed to the latter IMO


---
demerphq

<Elian> And I do take a kind of perverse pleasure in having an OO assembly language...

Replies are listed 'Best First'.
Re: Re: Re: Re: RFC - inplace upgrade for Tie::SortHash
by Limbic~Region (Chancellor) on Sep 05, 2003 at 17:01 UTC
    demerphq,
    I have to disagree.
    defined $self->[ARRAY][$index] ? $self->[ARRAY][$index] : undef;
    Is equivalent to:
    if (defined $self->[ARRAY][$index]) { return $self->[ARRAY][$index]; } else { return undef; }
    Cheers - L~R

      Yes, and its exactly equivelent to

      return $self->[ARRAY][$index];

      What is the point of the if in your code? If the values of $self->[ARRAY][$index] is defined then we return the value. If its not then we return undef. Whats the point? The value of $self->[ARRAY][$index] should simply be returned. There is no difference. (Except the one is more efficient and less confusing.)

      Consider this using different values:

      sub foo { my $x=shift; if ($x=10) { return 10; } else { return $x; } }

      Which is just plain silly isn't it?


      ---
      demerphq

      <Elian> And I do take a kind of perverse pleasure in having an OO assembly language...
        demerphq,
        Ok - you are embarrasingly correct. My issue was confusing hashes and arrays. Trying to avoid auto-vivication. /me hangs his head in shame, but thanks demerphq for being persistent until the lightbulb went off.

        Cheers - L~R