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=-0.5 required=3.0 tests=BAYES_05 autolearn=ham autolearn_force=no version=3.4.5-pre1 Path: eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Paul Rubin Newsgroups: comp.lang.ada Subject: Re: Ada and "early return" - opinion/practice question Date: Tue, 16 Mar 2021 02:26:46 -0700 Organization: A noiseless patient Spider Message-ID: <87tupb30vd.fsf@nightsong.com> References: <38356aa9-b8b0-4e0b-a490-99e7b239d0b1n@googlegroups.com> <87im5sutdt.fsf@nightsong.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: reader02.eternal-september.org; posting-host="5e605c98745901e728572b69920e311b"; logging-data="31084"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18YZD6ThTLt6rnwqg+iX+QW" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) Cancel-Lock: sha1:XvqQQyUPoTGrgATtvmTfb08Byhk= sha1:mvESewJse31BKB8MAgk4L2p8u4w= Xref: reader02.eternal-september.org comp.lang.ada:61553 List-Id: "Randy Brukardt" writes: > We're not talking about "normal control flow" here; we're talking about > error conditions that typically represent a programming mistake. It's fine > to use exceptions for that, because they should never occur. Ok, sure, that's the purpose of exceptions. But the original question didn't give the impression that was the situation. It looked more like a normal error condition, such as unsuccessfully trying to open a network connection to somewhere. Handling that condition is normal control flow rather than recovering from a programming error (network interruptions are routine situations). The issue then is not just possible slow performance of exceptions, but also the added difficulty of understanding what the program is doing when exceptions are in play. An exception is in some ways a goto on steroids. Without checked exceptions you don't know where the handler is, and experienced with Java showed checked exceptions are such a pain that all kinds of special unchecked exceptions ended up being allowed. Does Ada have checked exceptions? That basically means any function that can raise an exception must declare what exceptions it can raise, and that list is also inherited from anything below it in the call tree. The Haskell fashion these days is to write functions, when possible, that never raise exceptions. For example, the "head" function (which gives back the first element of a list) raises an exception if its arg is an empty list. It is a very basic function in the standard Haskell library that was once used freely, but now its use is considered suspect. I think that Ada has a way of verifying with Spark that a function can never raise an exception, and that this is an important use of Spark.