From: jgv@swl.msd.ray.com (John Volan)
Subject: Re: "Subtract C, add Ada"
Date: Wed, 25 Jan 1995 14:19:07 GMT
Date: 1995-01-25T14:19:07+00:00 [thread overview]
Message-ID: <D2yt3w.4Ip@swlvx2.msd.ray.com> (raw)
In-Reply-To: lawnm.33.00146988@leeds.ac.uk
lawnm@leeds.ac.uk (N. Mellor) writes:
>This seems a valid point to me, particularly because +=
>simplifies and clarifies expressions, particularly complex ones. I
>don't think there'd be much disagreement over this one, for example:
>
>foo( bar( zot( element + 1))) = foo( bar(zot( element + 1))) + 1;
>
>foo( bar( zot(element + 1))) += 1;
>
>The second clearly saves on mistakes and makes the whole line more readable.
>To check the first, you need to do a mechanical, lexeme by lexeme comparison
>of the two array references to check that they're the same-- not a great score
>in the readability stakes. This is a clear example of C shorthand being
>superior, in some situations, in some respects, to Ada's straightforwardness.
>It isn't the whole story, of course.
Of course it isn't. One way of tackling this kind of situation
without introducing new operators into the language is to exploit
renaming declarations:
declare
Foobarzot : Whatever_Type renames Foo(Bar(Zot(Element+1)));
begin
Foobarzot := Foobarzot + 1;
end;
"Foobarzot" thus becomes a convenient local temporary alias for the
object otherwise known by the more cumbersome name of
"Foo(Bar(Zot(Element+1)))". This makes the incrementing assignment
just as easy to read as any C-like alternative. It also makes it clear
that the same object is being referenced on both sides of the
assignment, without needing to duplicate "Foo(Bar(Zot(Element+1)))"
(which is obviously error-prone). Additionally, it makes it clear that
the computations that occur in "Foo(Bar(Zot(Element+1)))" should happen
only once, before incrementing the resulting object.
>BUT...self-referencing assignments are a very common idiom in just about any
>language, and it's only right that we should at least discuss ways of
>expressing them elegantly. Though on the whole C/C++ haven't seen me for dust,
>I do miss +=, -= and algebraic ifs (the ?: operator pair). All of these can
>usefully reduce complexity in very busy and convoluted bits of code.
>
>Of course, there are other good reasons for not having these goodies.
>One is that they're not essential, and too many operators can increase the
>complexity of the language disastrously. One of the problems with C is its
>plethora of operators and the consequent complexity of the operator precedence
>rules. Add to that C's blurring of the distinction between statements and
>expressions and you have serious readability problems, whether for novices or
>experts.
I couldn't aggree with you more.
>The bottom line is that it's simple to write an Ada procedure which safely
>adds or subtracts its second argument from its first, which can be defined as
>an in out parameter:
>
>procedure self-add(in out var, in expression) is
> var := var + expression;
>end self-add;
>
>and use it as in
>
>self-add( foo( bar( zot( element + 1))) , 1);
Er, properly speaking, this should be something like:
procedure Add (To : in out Whatever_Type; Addend : in Whatever_Type) is
begin
To := To + Addend;
end Add;
And then it could be used as in:
Add (To => Foo(Bar(Zot(Element+1))), Addend => 1);
In fact, the declare-block I wrote above could be viewed as an "inline"
equivalent to this procedure call.
>Any other thoughts?
>
>Nick Mellor
>Leeds
Hope this helps.
-- John Volan
--------------------------------------------------------------------------------
Me : Person :=
(Name => "John G. Volan", E_Mail_Address => "jgv@swl.msd.ray.com",
Employer => "Raytheon", Affiliation => "Enthusiastic member of Team-Ada!",
Shameless_Controversial_Marketing_Slogan_For_Favorite_Language =>
"<<<< Ada95: The World's *FIRST* Internationally-Standardized OOPL >>>>",
Humorous_Language_Lawyerly_Disclaimer =>
"These opinions are undefined by my employer, so using them would be " &
"totally erroneous ... or would that be a bounded error? :-) ");
--------------------------------------------------------------------------------
next prev parent reply other threads:[~1995-01-25 14:19 UTC|newest]
Thread overview: 85+ messages / expand[flat|nested] mbox.gz Atom feed top
1995-01-20 10:20 "Subtract C, add Ada" R.A.L Williams
1995-01-20 13:22 ` Renaud HEBERT
1995-01-24 3:35 ` David Moore
1995-01-25 5:38 ` Robert Dewar
1995-01-28 16:35 ` Jules
1995-01-29 8:06 ` Matt Kennel
1995-01-30 5:31 ` Michael Feldman
1995-01-31 22:22 ` David O'Brien
1995-01-24 20:23 ` N. Mellor
1995-01-25 8:50 ` Robb Nebbe
1995-01-25 14:19 ` John Volan [this message]
1995-01-26 5:07 ` Samuel Mize
1995-01-26 18:51 ` Mark A Biggar
1995-01-21 15:18 ` Robert Dewar
1995-01-21 21:03 ` David O'Brien
1995-01-23 3:09 ` Jay Martin
1995-01-23 12:50 ` Andrew McConnell
1995-01-24 0:54 ` Matt Kennel
1995-01-25 17:03 ` Norman H. Cohen
1995-01-26 1:13 ` Dr. Richard Botting
1995-01-26 14:32 ` Anders Juul Munch
1995-01-24 0:17 ` Bob Kitzberger
1995-01-23 20:46 ` Robert Firth
1995-01-24 14:25 ` Samuel Mize
1995-01-25 7:27 ` David O'Brien
1995-01-25 12:14 ` Robert A Duff
1995-01-25 5:57 ` David O'Brien
[not found] ` <3g9rf0$71k@Starbase.NeoSoft.COM>
1995-01-28 21:08 ` David O'Brien
1995-01-31 18:07 ` Samuel Mize
1995-02-01 10:23 ` Samuel Mize
1995-01-30 0:24 ` Mark S. Hathaway
1995-01-31 3:30 ` Jay Martin
1995-02-01 13:25 ` Jesper Kaagaard
-- strict thread matches above, loose matches on Subject: below --
1995-02-10 13:49 R.A.L Williams
[not found] <3gsr0e$oin@miranda.gmrc.gecm.com>
1995-02-07 16:58 ` Mark S. Hathaway
1995-02-08 7:39 ` Travis C. Porco
1995-02-08 16:07 ` Fred J. McCall
1995-02-08 21:30 ` Garlington KE
1995-01-31 9:34 R.A.L Williams
1995-02-01 16:45 ` Charles H. Sampson
1995-01-23 8:49 R.A.L Williams
1995-01-25 23:18 ` Charles H. Sampson
1995-01-20 9:33 R.A.L Williams
[not found] <3fgphd$sc3@rational.rational.com>
1995-01-20 5:51 ` RonaldS60
1995-02-07 13:55 ` Robert C. Soong
[not found] <3fdcoi$chn@miranda.gmrc.gecm.com>
1995-01-20 5:01 ` Samuel Mize
1995-01-20 22:07 ` Garlington KE
1995-01-24 5:02 ` R_Tim_Coslet
[not found] <3etund$hnr@miranda.gmrc.gecm.com>
1995-01-12 9:56 ` Erik Svensson
1995-01-12 14:44 ` Norman H. Cohen
1995-01-13 1:51 ` David O'Brien
1995-01-13 12:38 ` Laurent Gasser
1995-01-13 20:53 ` John DiCamillo
[not found] ` <3f8fnf$c8p@gamma.ois.com>
1995-01-16 11:02 ` Matt Kennel
[not found] ` <milodD2IFpG.329@netcom.com>
1995-01-17 21:39 ` R. William Beckwith
[not found] ` <3fa11q$sdh@gnat.cs.nyu.edu>
1995-01-16 20:20 ` David Moore
1995-01-14 0:24 ` David O'Brien
1995-01-20 4:43 ` Samuel Mize
1995-01-21 20:28 ` David O'Brien
1995-01-22 21:12 ` Robert Dewar
1995-01-23 18:35 ` Norman H. Cohen
1995-01-23 19:18 ` John Cosby - The Coz
1995-01-24 14:11 ` Samuel Mize
1995-01-14 10:37 ` Keith Thompson
[not found] ` <3fcjgt$b0v@cronkite.seas.gwu.edu>
1995-01-16 18:47 ` Robert Dewar
[not found] ` <D2It0r.4rp@inmet.camb.inmet.com>
1995-01-17 14:11 ` Norman H. Cohen
1994-12-30 16:06 Mitch Gart
1995-01-03 19:04 ` whiting_ms@corning.com (Matt Whiting)
1995-01-05 4:31 ` Michael Feldman
1995-01-04 21:40 ` Fred McCall
1995-01-05 4:30 ` Richard Pattis
1995-01-05 16:07 ` Kevin Weise
1995-01-06 13:06 ` Jahn Rentmeister
1995-01-06 16:47 ` Laurent Gasser
1995-01-06 17:29 ` David Weller
1995-01-06 17:30 ` David Weller
1995-01-10 18:28 ` Bob Kitzberger
1995-01-06 23:36 ` Kenneth Almquist
1995-01-04 22:45 ` Jay M. Martin
1995-01-05 4:37 ` Michael Feldman
1995-01-05 18:08 ` Jay Martin
1995-01-05 23:56 ` Robert Dewar
1995-01-08 8:04 ` Jay Martin
1995-01-06 0:07 ` Michael M. Bishop
1995-01-10 21:30 ` Jay Martin
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox