develooper Front page | perl.perl5.porters | Postings from June 2008

Re: [perl #56150] return return

Thread Previous | Thread Next
From:
Ben Morrow
Date:
June 23, 2008 08:18
Subject:
Re: [perl #56150] return return
Message ID:
kiq4j5-4r3.ln1@osiris.mauzo.dyndns.org

Quoth mark@mark.mielke.cc (Mark Mielke):
> 
> Another common bit of code that I've written is:
> 
> sub foo
> {
>     my($this) = @_;
>     exists($this->{'foo'}) ? $this->{'foo'} : do {
>         ... expensive calculations ...
>         $this->{'foo'} = ...;
>     };
> }
> 
> This introduces the other statement that is frequently used to return 
> the last value without a return -  do{}. The above code is not 
> significantly improved by adding return anywhere.

I disagree. IMHO

    sub foo {
        my ($this) = @_;

        exists $this->{foo} and return $this->{foo};

        ...expensive calculations...

        return $this->{foo} = ...;
    }

is clearer in at least two important ways.

Ben

-- 
               We do not stop playing because we grow old; 
                  we grow old because we stop playing.
                            ben@morrow.me.uk

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About