× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Actually,  I kind of like that _ASSUMING_ there's some sort of cleanup that 
needs to be done before the return.  Having a RETURN in a subroutine might make 
sense.

But your example certainly shows "following the letter of the law but not the 
intent."


Some interesting not RPG discussions about this:
http://c2.com/cgi/wiki?SingleFunctionExitPoint

I tend to use multiple returns as guard clauses:
http://c2.com/cgi/wiki?GuardClause


Example from the above web page:
Here is a sample of code using guard clauses ...

  public Foo merge (Foo a, Foo b) {
    if (a == null) return b;
    if (b == null) return a;
    // complicated merge code goes here.
  }


Some style guides would have us write this with a single return as follows ...

  public Foo merge (Foo a, Foo b) {
    Foo result;
    if (a != null) {
      if (b != null) {
        // complicated merge code goes here.
      } else {
        result = a;
      }
    } else {
      result = b;
    }
    return result;
  }



Charles Wilt
--
iSeries Systems Administrator / Developer
Mitsubishi Electric Automotive America
ph: 513-573-4343
fax: 513-398-1121
 

> -----Original Message-----
> From: rpg400-l-bounces@xxxxxxxxxxxx
> [mailto:rpg400-l-bounces@xxxxxxxxxxxx]On Behalf Of Hewitt, Rory
> Sent: Thursday, July 28, 2005 1:27 PM
> To: rpg400-l@xxxxxxxxxxxx
> Subject: Single return point (Was: No Subroutines...)
> 
> 
> 
> I agree totally. I've even come across code where, in order 
> to 'enforce'
> the 'single-entry, single-return' maxim, you get this within a
> subprocedure:
> 
> if (some condition);
>   exsr return;
> endif;
> 
> if (another);
>   exsr return;
> endif;
> 
> if (yet another condition);
>   exsr return;
> endif;
> 
> ... (repeated for lots of other code)..
> 
> return begsr;
>   return;
> endsr;
> 
> *pssr begsr;
> (error processing)
> exsr return;
> endsr;
> 
> Now I can see that if you want to have some exit-specific code, then
> maybe it's a good method (because you can add your code before the
> return statmnent within the  return subroutine), but on the downside,
> you have multiple if's (not nested in this example, but they probably
> are in real life!), the equivalent of lots of RETURN's throughout the
> procedure, AND a subroutine, which  some on this forum will 
> consider the
> biggest sin of all :-)
> 
> But there's a single return point, so THAT's ok.
> 
> Rory
> 


As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.