comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@world.std.com>
Subject: Re: scope and/or parameters (beginner)
Date: 1999/04/22
Date: 1999-04-22T00:00:00+00:00	[thread overview]
Message-ID: <wccaew0o6bn.fsf@world.std.com> (raw)
In-Reply-To: 371c4201.2003123297@news.dsuper.net

fluffy_dong@dsuper.net writes:

> I know that and I am curious as to why the people who designed Ada
> made it this way, as opposed to the way that I described.  If there is
> no OUT then it would/should not matter what is done to the value
> passed because it's not coming back.  It would/should be treated as an
> idependent copy of the variable passed.  I know that is not the way it
> works.  Why not? (Don't answer. It's been answered below.)

Even if all parameters were always passed by copy, the language
designers would *still* have made 'in' parameters constant inside the
called procedure.  Suppose I wanted an 'in out' parameter, but I forgot
to say 'in out'.  The Ada rule saves me, because when I assign the new
value to the parameter, I get a compilation error.  Note that it's
irrelevant whether the formal parameter is assigned by a direct
assignment statement, or by calling another procedure which in turn has
an 'in out' parameter.  (Constant means constant, and, like Robert, I'm
surprised that you would think passing it to another procedure would
somehow turn that off.)

Furthermore, constants generally make the code more readable, because if
you know something is constant, you don't have to worry about it
changing.  That's true of local variables, and it's just as true of
formal parameters.  So of course formal parameters should default to
being constant.  (If I had designed the language, I would have done the
same for local variables -- "X: Integer := 10;" would declare a
constant, and "X: var Integer := 10;" would declare a variable.)

And furthermore, the need to modify a parameter as a temp inside the
procedure is rare -- if you need to do that, it's no big deal to declare
a local variable and initialize it to the value of the parameter.  And
doing that makes it clear what's going on.

- Bob
-- 
Change robert to bob to get my real email address.  Sorry.




  parent reply	other threads:[~1999-04-22  0:00 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-04-02  0:00 scope and/or parameters (beginner) fluffy_pink
1999-04-03  0:00 ` Matthew Heaney
1999-04-05  0:00 ` Corey Ashford
1999-04-05  0:00   ` fluffy_doo
1999-04-06  0:00     ` Matthew Heaney
1999-04-08  0:00     ` czgrr
1999-04-10  0:00       ` fluffy_puff
1999-04-12  0:00       ` dennison
1999-04-13  0:00         ` Robert Dewar
1999-04-13  0:00         ` czgrr
1999-04-13  0:00           ` Robert Dewar
1999-04-14  0:00             ` czgrr
1999-04-14  0:00               ` Robert Dewar
1999-04-15  0:00                 ` czgrr
1999-04-15  0:00                   ` Robert Dewar
1999-04-14  0:00               ` dennison
1999-04-13  0:00     ` Robert A Duff
1999-04-14  0:00       ` Robert Dewar
1999-04-14  0:00         ` Hyman Rosen
1999-04-14  0:00           ` dennison
1999-04-14  0:00             ` Hyman Rosen
1999-04-14  0:00               ` dennison
1999-04-14  0:00                 ` Hyman Rosen
1999-04-15  0:00                   ` dennison
1999-04-15  0:00                     ` Robert Dewar
1999-04-15  0:00                       ` dennison
1999-04-15  0:00                       ` Hyman Rosen
1999-04-15  0:00           ` Robert Dewar
1999-04-15  0:00             ` Hyman Rosen
1999-04-15  0:00               ` Robert Dewar
1999-04-15  0:00                 ` Hyman Rosen
1999-04-16  0:00               ` Rakesh Malhotra
1999-04-15  0:00       ` fluffy_dong
1999-04-15  0:00         ` Robert Dewar
1999-04-15  0:00           ` dennison
1999-04-15  0:00             ` fluffy_dong
1999-04-16  0:00               ` Robert Dewar
1999-04-16  0:00                 ` Fraser Wilson
1999-04-16  0:00                   ` Gautier.DeMontmollin
1999-04-20  0:00                     ` Nick Roberts
1999-04-21  0:00                     ` fraser
1999-04-22  0:00               ` Robert A Duff [this message]
1999-04-22  0:00                 ` Larry Kilgallen
1999-04-16  0:00         ` Samuel Mize
replies disabled

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