From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.5-pre1 Path: eternal-september.org!reader02.eternal-september.org!nntp-feed.chiark.greenend.org.uk!ewrotcd!newsfeed.xs3.de!news.jacob-sparre.dk!franka.jacob-sparre.dk!pnx.dk!.POSTED.rrsoftware.com!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: Ada and "early return" - opinion/practice question Date: Tue, 16 Mar 2021 02:08:58 -0500 Organization: JSA Research & Innovation Message-ID: References: <38356aa9-b8b0-4e0b-a490-99e7b239d0b1n@googlegroups.com> Injection-Date: Tue, 16 Mar 2021 07:08:59 -0000 (UTC) Injection-Info: franka.jacob-sparre.dk; posting-host="rrsoftware.com:24.196.82.226"; logging-data="3213"; mail-complaints-to="news@jacob-sparre.dk" X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5931 X-RFC2646: Format=Flowed; Response X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.7246 Xref: reader02.eternal-september.org comp.lang.ada:61543 List-Id: "Dmitry A. Kazakov" wrote in message news:s2o3ud$19im$1@gioia.aioe.org... > On 2021-03-15 17:46, John McCabe wrote: ... > I see nothing wrong with it. In Ada: > > function fn () return is > begin > if then > return ; > elsif then > return ; > elsif then > return ; > else --Only get here if everything's good... > > return ; > end fn; I agree with Dmitry; it's not unusual to find this sort of structure in my code (usually raising exceptions, though). With Ada 2012, some of those conditions probably ought to be in the precondition, so that people can see what not to do when writing their code. That would be: function fn () return with Pre => (not ) and then (not ); It's not always easy to decide where to draw the line, but a rule of thumb that I use is that the precondition should depend only on the parameters (not global state) and it should be easy to describe (preferably with a simple function call). If those are met, then it probably should be in the precondition -- and then the body of the function can assume the precondition is true. Randy.