From: Niklas Holsti <niklas.holsti@tidorum.invalid>
Subject: Re: If a routine should return two results, how should it be done?
Date: Sat, 26 Jul 2014 21:53:50 +0300
Date: 2014-07-26T21:53:50+03:00 [thread overview]
Message-ID: <c3ibpuFsm87U1@mid.individual.net> (raw)
In-Reply-To: <lr0qb7$549$1@speranza.aioe.org>
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
. @ .
next prev parent reply other threads:[~2014-07-26 18:53 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-26 18:00 If a routine should return two results, how should it be done? Victor Porton
2014-07-26 18:53 ` Niklas Holsti [this message]
2014-07-26 18:57 ` Victor Porton
2014-07-26 19:21 ` Peter Chapin
2014-07-26 19:37 ` Dan'l Miller
2014-07-26 20:10 ` Shark8
2014-07-26 20:42 ` Victor Porton
2014-07-26 20:44 ` Victor Porton
2014-07-27 11:59 ` anon
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox