comp.lang.ada
 help / color / mirror / Atom feed
From: Niklas Holsti <niklas.holsti@tidorum.invalid>
Subject: Re: Ada 2012: In-out parameters for functions
Date: Sun, 05 May 2013 18:09:11 +0300
Date: 2013-05-05T18:09:11+03:00	[thread overview]
Message-ID: <aunb0nFir95U1@mid.individual.net> (raw)
In-Reply-To: <CDAC1492.2D8D2%yaldnif.w@blueyonder.co.uk>

On 13-05-05 15:52 , Bill Findlay wrote:
> On 05/05/2013 12:11, in article op.wwlyp5ymule2fv@cardamome, "Yannick
> Duchêne   (Hibou57)" <yannick_duchene@yahoo.fr> wrote:
> 
>> Le Sun, 05 May 2013 12:24:50 +0200, Niklas Holsti
>> <niklas.holsti@tidorum.invalid> a écrit:
>>
>>> How about reusing the mode keywords:
>>>
>>>    Proc (
>>>       In_Param  => in A,
>>>       Out_Param => out B,
>>>       In_Out_Param => in out C);
>>>
>>
>>> An alternative, perhaps more English-like, […]
>>>
>>>    Proc (
>>>       in In_Param  => A,
>>>       out Out_Param => B,
>>>       in out In_Out_Param => C);
>>>
>>
>> But may be the first is more Chinese‑like :P (I don't know, I don't know
>> Chinese)
>>
>> Not joking, the first looks better to me, it better express what it means
>> as the mode is closer to the actual parameter which is the subject of the
>> mode (the same way at the declaration, it is closer to the type, which is
>> the best to me for a similar reason).
>>
>> Seems this topic was not discussed at all for Ada 2012.
> 
> I'm glad to hear it, because the idea is bonkers.

"Bonkers" is a bit harsh :-)

> Declarations collect relevant info to one easily found place in the code,
> instead of having it splattered around at random.

The question is if some redundancy in the source code is useful -- Ada
users normally reply "yes" -- and what kind and amount of redundancy is
useful -- here our opinions can differ.

> These suggestions about parameter mode make no more sense than suggesting
> that, instead of declaring:
> 
>   I : Integer; S ; String;
> 
> One should instead have to write things like:
> 
>    I% := I% + 1;
>    S$ := "";
> 
> (A la BASIC)

... or a-la type-revealing "Hungarian notation". I hate such redundant
declaration of variable types in variable identifiers, so we agree on
that kind of redundancy being bonkers (for Ada, at least).

Repeating the parameter mode in calls is a different kind of redundancy,
with a bit of the flavour of SPARK information-flow analysis.

By specifying the modes in the call, the caller is stating a kind of
contract, or expectation: "In this call, I expect In_Param not to be
modified (even if the actual parameter is a non-constant object), but I
do expect that Out_Param will be modified, and that In_Out_Param may be
modified." This is problem-domain information (semantics). If the actual
modes are different (perhaps through a recent change to the subprogram
profile), there is quite likely something wrong, just as if the types of
the actuals did not match the formals.

Is this redundancy likely to help discover errors, or is it just a nuisance?

For Ada, I think Hungarian notation is a nuisance, because Ada programs
should use problem-oriented types, which means that a change to the
underlying physical type, in the type declaration alone, should be
possible without changes to other parts of the source code. Avoiding
Hungarian notation works in Ada because of strong typing. In C/C++,
where all integer types are implicitly interconvertible, I can see some
good in Hungarian notation, since it keeps the type of each variable
visible as one writes expressions using that variable, which may help
one write expressions that have the intended effect.

However, the use of parameter mode notations in Ada calls is not likely
to become a nuisance. If the profile of the subprogram being called is
changed so that some parameter modes change, it seems to me highly
likely that all call sites must at least be inspected to see if they
still have the intended effects, and most call sites must probably be
modified to take the new parameter modes into account. Without parameter
modes in calls, the compiler can point out only some kinds of mode
conflicts, such as an uninitialized variable as the actual parameter for
an "in" or "in out", or a constant object as the actual parameter for an
"out" or "in out". If the calls specify parameter modes, the compiler
can point out all mode conflicts.

I believe I have made some Ada coding errors that would have been
revealed by mode notations in calls. I don't remember the exact
examples, but I think one concerned a procedure in which an "in"
parameter was changed to an "in out" parameter, because some new uses of
the subprogram required it -- but then some old uses no longer worked,
because they assumed that the actual for this parameter would not be
changed. And the actual was a non-constant object, so the compiler saw
nothing wrong in its use for an in-out parameter.

-- 
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
      .      @       .




  reply	other threads:[~2013-05-05 15:09 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-01 16:28 Ada 2012: In-out parameters for functions dptrash
2013-05-01 17:27 ` Shark8
2013-05-01 19:04 ` Yannick Duchêne (Hibou57)
2013-05-01 19:37   ` Dmitry A. Kazakov
2013-05-01 19:58     ` Yannick Duchêne (Hibou57)
2013-05-02  6:41       ` Dmitry A. Kazakov
2013-05-02  7:11         ` Yannick Duchêne (Hibou57)
2013-05-01 23:37 ` Peter C. Chapin
2013-05-03 10:48 ` anon
2013-05-03 11:04   ` Simon Clubley
2013-05-03 11:32   ` Simon Wright
2013-05-03 11:42   ` Yannick Duchêne (Hibou57)
2013-05-03 11:54     ` Yannick Duchêne (Hibou57)
2013-05-03 23:29       ` Randy Brukardt
2013-05-04  1:02         ` Adam Beneschan
2013-05-05  5:16           ` Randy Brukardt
2013-05-05 10:24         ` Niklas Holsti
2013-05-05 11:11           ` Yannick Duchêne (Hibou57)
2013-05-05 12:52             ` Bill Findlay
2013-05-05 15:09               ` Niklas Holsti [this message]
2013-05-05 19:23                 ` Yannick Duchêne (Hibou57)
2013-05-05 20:37                   ` Niklas Holsti
2013-05-07  0:30                 ` Randy Brukardt
2013-05-07  2:36                   ` Yannick Duchêne (Hibou57)
2013-05-05 19:45               ` Yannick Duchêne (Hibou57)
2013-05-06 15:40               ` Adam Beneschan
2013-05-06 16:17                 ` Bill Findlay
2013-05-06 16:47                   ` Adam Beneschan
2013-05-06 18:43                     ` Bill Findlay
2013-05-07  0:07                     ` Dennis Lee Bieber
2013-05-07  2:34                       ` Yannick Duchêne (Hibou57)
2013-05-07  0:26             ` Randy Brukardt
2013-05-06 15:26           ` Adam Beneschan
2013-05-07  0:36             ` Randy Brukardt
2013-05-07  3:59           ` Yannick Duchêne (Hibou57)
2013-05-07  4:13             ` Yannick Duchêne (Hibou57)
2013-05-07 11:52             ` Yannick Duchêne (Hibou57)
2013-05-03 11:45   ` AdaMagica
2013-05-03 23:54     ` Randy Brukardt
2013-05-04  6:58       ` J-P. Rosen
2013-05-04  7:21         ` Dmitry A. Kazakov
2013-05-04 17:58           ` J-P. Rosen
2013-05-04  7:40         ` Yannick Duchêne (Hibou57)
2013-05-04  8:05           ` Simon Wright
2013-05-04 17:55           ` J-P. Rosen
2013-05-04  0:40   ` Keith Thompson
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox