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

RE: [perl #56150] return return

Thread Previous | Thread Next
From:
KONOVALOV, Vadim ** CTR **
Date:
June 23, 2008 11:26
Subject:
RE: [perl #56150] return return
Message ID:
D16F05D0CAAA234BA2B753B80DE6100D9B1D7E@DEEXC1U02.de.lucent.com
> > For everyone else, putting in an explicit `return` is a way to
> > state explicitly that “yes, I really did mean for this value to
> > be returned, I did not just forget to suppress it.”
> >   
> 
> See above. There are alternative ways to do this. I'll often do:
> 
> sub NAME
> {
>     ... declarations ...
> 
>     ... bodies ...
> 
>    $result;
> }

IMO the habbit to write

sub foo {
   ...
   $bar;
}

is only syntax preference of writing 

sub foo {
   ...
   return $bar;
}

.. so I consider both to be exactly the same. On the contrary, if the following sub:

sub foo {
  do_something_useful();
}

... happens to return something as a side effect, this is just a wasted CPU due to mis-optimization, (fortunately small mis-optimization) , which happens quite often (unfortunately)

For sure 99,9% of people do not mean it as 
sub foo {
  return do_something_useful();
}

and even if they do, this *is* a bat habbit because this is a potential pain for future readings of this code, either by author or maintainer.

Just my RUR0.02

BR,
Vadim.

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