From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,fc52c633190162e0 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: Use of declare blocks Date: Wed, 21 Mar 2007 16:29:57 -0500 Organization: Jacob's private Usenet server Message-ID: References: <1172144043.746296.44680@m58g2000cwm.googlegroups.com> <1172161751.573558.24140@h3g2000cwc.googlegroups.com> <546qkhF1tr7dtU1@mid.individual.net> <5ZULh.48$YL5.40@newssvr29.news.prodigy.net> <4eeMh.16400$bb1.2557@newssvr17.news.prodigy.net> <460198f2$0$24601$39db0f71@news.song.fi> NNTP-Posting-Host: static-69-95-181-76.mad.choiceone.net X-Trace: jacob-sparre.dk 1174512504 27672 69.95.181.76 (21 Mar 2007 21:28:24 GMT) X-Complaints-To: news@jacob-sparre.dk NNTP-Posting-Date: Wed, 21 Mar 2007 21:28:24 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1807 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1807 Path: g2news1.google.com!news4.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!t-online.de!tiscali!newsfeed1.ip.tiscali.net!proxad.net!feed.ac-versailles.fr!news.ecp.fr!news.jacob-sparre.dk!pnx.dk!not-for-mail Xref: g2news1.google.com comp.lang.ada:14582 Date: 2007-03-21T16:29:57-05:00 List-Id: "Niklas Holsti" wrote in message news:460198f2$0$24601$39db0f71@news.song.fi... > Randy Brukardt wrote: > > > I use declare blocks extensively to reduce the scope of temporary variables > > in subprograms. They're especially important when the object exists just to > > take an unused out parameter, because they greatly reduce the need to come > > up with names for the objects. I often have code like: > > > > declare > > Junk : Index; > > begin > > Insert_Something (..., Result => Junk); > > end; > > > > where the result isn't needed by the following code. > > How about a language extension to omit unused out parameters, for example > > Insert_Something (..., Result => <>); > > Perhaps even allowing declaration of optional out parameters, as in > > procedure Insert_Something (..., Result : out Index := <>); > > and then a call of Insert_Something could omit Result entirely. I think both of these would be a tough sell. I'm sure some people would feel that having an out parameter that you don't need is a design flaw, and we shouldn't be encouraging design flaws. They come up a lot of foreign library interfaces, and I suppose the argument would be that they should be wrapped and hidden (even if that is too expensive for the particular usage). After all, once of the good things about Ada is that you have to do something explicit to ignore returned values (including error returns). If they're mapped as out parameters, you have to write code to discard them (like the above). If they're mapped as exceptions, you have to handle and ignore (with a null handler) the exception (or all exceptions). Both of these are obvious when reading the code. It's a lot harder to detect an error of omission than an error of commission. This is similar in some ways to the arguments against out parameters in functions, where the possibility of unnoticed order dependencies and tricky expressions makes some people uncomfortable. Randy.