comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: Ada 2012: In-out parameters for functions
Date: Mon, 6 May 2013 08:40:48 -0700 (PDT)
Date: 2013-05-06T08:40:48-07:00	[thread overview]
Message-ID: <19a6badd-ed0f-4023-9100-b9ab653a7f23@googlegroups.com> (raw)
In-Reply-To: <CDAC1492.2D8D2%yaldnif.w@blueyonder.co.uk>

On Sunday, May 5, 2013 5:52:18 AM UTC-7, Bill Findlay wrote:
> On 05/05/2013 12:11, in article op.wwlyp5ymule2fv@cardamome, "Yannick

> >> How about reusing the mode keywords:
> 
> >>    Proc (
> >>       In_Param  => in A,
> >>       Out_Param => out B,
> >>       In_Out_Param => in out C);

>> Seems this topic was not discussed at all for Ada 2012.

> I'm glad to hear it, because the idea is bonkers.
> 
> Declarations collect relevant info to one easily found place in the code,
> instead of having it splattered around at random.

No, I don't think you understand.  This isn't a declaration.  The place where you tell the compiler what the parameter mode is would be the same place where it's always been, when the called subprogram is declared.  Allowing mode declarations in the call would serve two purposes: (1) to alert someone reading the program to the fact that the function call may change one of its parameters, and (2) as a check.  I could envision someone writing

   if Some_Function (Param => in X) then ...

because they're assuming the function call won't change X.  But if it turns out they've made a mistake, or if (due to overloading) the function actually called is a different one from what the programmer thought, or if another programmer unknowingly changes the declaration of Some_Function later, then the compiler would catch the error.  Adding a parameter mode in a call could *not* change the meaning of a program; the effect would be exactly the same if it doesn't cause the compiler to reject the program.

I actually think #1 is more important, because I can attest to the fact that a function call that changes its parameter can make code really difficult to read.  Pascal allows this, and I can't count the number of times I've misunderstood what Pascal code does because I see a function call with a variable parameter that looks like it's just testing the value, when in reality it's changing the variable.  This is partly due to poor naming choices by other programmers, to be sure.  But I believe it would be very valuable for a programmer to be able to put something in the code to help clarify their intentions.  (And it's harder to do this with a comment in Ada than in Pascal, since Pascal has in-line comments.)

                             -- Adam


  parent reply	other threads:[~2013-05-06 15:40 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
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 [this message]
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