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!aioe.org!pBWEO6hi52oGFheO/GY5ag.user.gioia.aioe.org.POSTED!not-for-mail From: Stephen Leake Newsgroups: comp.lang.ada Subject: Re: Ada and "early return" - opinion/practice question Date: Mon, 15 Mar 2021 10:31:27 -0700 Organization: Aioe.org NNTP Server Message-ID: <86eegge32o.fsf@stephe-leake.org> References: <38356aa9-b8b0-4e0b-a490-99e7b239d0b1n@googlegroups.com> NNTP-Posting-Host: pBWEO6hi52oGFheO/GY5ag.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain X-Complaints-To: abuse@aioe.org User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (windows-nt) X-Notice: Filtered by postfilter v. 0.9.2 Cancel-Lock: sha1:FaYecACRjTkrD3lktbClBIk0j+c= Xref: reader02.eternal-september.org comp.lang.ada:61527 List-Id: John McCabe writes: > I hope this isn't a FAQ (it's hard to find relevant articles) but can > someone guide me on the 'normal' treatment in Ada style of what > appears to be referred to (by C/C++ programmers) as early-return. > > For example, you have a C++ function (pseudo code sort of thing): > > fn() > { > if () > { > return ; > } > > if () > { > return ; > } > > if () > { > return ; > } > > // Only get here if everything's good... > > return ; > } > > I've probably mentioned this before, but it's a long time since I used > Ada in anger and I don't remember seeing stuff like that when I did > use Ada a lot; does anyone write stuff like that in Ada? Sometimes I write code that way, sometimes I have a Result variable that gets set along the way. The latter mostly when Result is a container of some sort, and parts of it get set at different points. I would tend to use an exception for "something bad", but that depends on the overall design. There are various maintenance issues on both sides; the summary is "editing existing code is a pain" :(. > Hope this is ok to ask! Sure; there are times when one style is overwhelmingly better (ie requiring matching end names); this just isn't one of them. -- -- Stephe