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=unavailable autolearn_force=no version=3.4.4 Path: border2.nntp.dca1.giganews.com!nntp.giganews.com!newspeer1.nac.net!feeder.erje.net!eu.feeder.erje.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Niklas Holsti Newsgroups: comp.lang.ada Subject: Re: If a routine should return two results, how should it be done? Date: Sat, 26 Jul 2014 21:53:50 +0300 Organization: Tidorum Ltd Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: individual.net g3BypxcPXBh/tEhH8j2ibAq7xMJtCRbXmjrFNICRCJ771+kdFb Cancel-Lock: sha1:KuRMRGmhDdTHBg2R8ZO110V7cvI= User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 In-Reply-To: Xref: number.nntp.dca.giganews.com comp.lang.ada:187909 Date: 2014-07-26T21:53:50+03:00 List-Id: On 14-07-26 21:00 , Victor Porton wrote: > If a routine should return two results, how should it be done? Pick any method you like (but not case 2, if you want to be compatible with pre-2012 Ada). > 1. procedure with two out arguments; > > 2. function with one out argument; > > 3. create specific record type for the result type of the function? > > What are advantages and disadvantages of each variant? The same as in any other language which offers these choices, which is most languages (well, for C you must use pointers for "out" and "in out", but logically it is the same thing). Oh, compared to C++ there is a small difference, in that Ada allows overloading on the result type; in C++ one would perhaps avoid choices 3 (and 2) for that reason. Personally I would first consider if the "two results" are logically connected in such a way that they actually represent one composite result, and then I would have a subprogram with one result -- no problem. Otherwise, I would use choice 1. Choice 2 would be acceptable to me only in very special cases, such as a random-number generator. -- Niklas Holsti Tidorum Ltd niklas holsti tidorum fi . @ .