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=0.6 required=5.0 tests=AC_FROM_MANY_DOTS,BAYES_00, HK_RANDOM_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,ec21c3c7cdc7ff3e X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!news.glorb.com!cycny01.gnilink.net!spamkiller.gnilink.net!gnilink.net!trnddc02.POSTED!20ae255c!not-for-mail Newsgroups: comp.lang.ada From: Justin Gombos Subject: Re: private types References: <1142279908.327131.230200@j52g2000cwj.googlegroups.com> User-Agent: slrn/0.9.8.1 (Linux) Message-ID: Date: Fri, 17 Mar 2006 22:50:30 GMT NNTP-Posting-Host: 129.44.77.228 X-Complaints-To: abuse@verizon.net X-Trace: trnddc02 1142635830 129.44.77.228 (Fri, 17 Mar 2006 17:50:30 EST) NNTP-Posting-Date: Fri, 17 Mar 2006 17:50:30 EST Xref: g2news1.google.com comp.lang.ada:3412 Date: 2006-03-17T22:50:30+00:00 List-Id: On 2006-03-17, Brian May wrote: > I am not sure how this: > > function exists return boolean is > > --Later assignment to found_it is evitable > -- > found_it : boolean := false; > > begin > > if some_precondition then > > found_it := some_other_condition; > > end if; > > return found_it; > > end exists; > > Is any better/worse then this: > > function exists return boolean is > > --Later assignment to found_it is evitable > -- > found_it : boolean; > > begin > > if some_precondition then > > found_it := some_other_condition; > > end if; > > return found_it; > > end exists; The second case is obviously careless, and as you say, unpredictible. The first case is a good approach, as is this alternative: function exists return boolean is --Later assignment to found_it is inevitable -- found_it : boolean; begin if some_precondition then found_it := some_other_condition; else found_it := a_different_condition; end if; return found_it; end exists; My main purpose was to put the spotlight on this foolish practice: function exists return boolean is --Later assignment to found_it is inevitable -- found_it : boolean := false; --needless and misleading initialization begin if some_precondition then found_it := some_other_condition; else found_it := a_different_condition; end if; return found_it; end exists; Users of the OPs API might be forced into this scenario if the API is constructed to force explicit initialization on instantiation. > It is possible a smart compiler might trigger a warning in the > second case - but this depends on you noticing the warning and > investigating it. There are cases when the compiler might get > confused and produce false positives or false negatives. > > Otherwise, the above problem is a problem that can only be found > either by careful inspection of the code or by proper testing. Sure there are multiple opportunities to find flaws; but the idea is to not depend on them more than we have to. -- PM instructions: do a C4esar Ciph3r on my address; retain punctuation.