From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,1d321b3a6b8bcab2 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 1995-01-24 12:23:43 PST Newsgroups: comp.lang.ada Path: nntp.gmd.de!newsserver.jvnc.net!howland.reston.ans.net!pipex!uknet!festival!leeds.ac.uk!news From: lawnm@leeds.ac.uk (N. Mellor) Subject: Re: "Subtract C, add Ada" Message-ID: Organization: University of Leeds Date: Tue, 24 Jan 1995 20:23:43 +0000 (GMT) References: <3fo2ot$su2@miranda.gmrc.gecm.com> <3fode9$dap@soleil.uvsq.fr> X-Newsreader: Trumpet for Windows [Version 1.0 Rev A] Date: 1995-01-24T20:23:43+00:00 List-Id: In article <3fode9$dap@soleil.uvsq.fr> hebert@prism.uvsq.fr (Renaud HEBERT) writes: >|> Personally, the lack of this sort of compactness in Ada, and things like >|> pre- and post-increment/decrement are one of my minor gripes about the >|> language. OK, its no big thing to write: >|> >|> P(I) := Q(I); >|> I := I + 1; >|> >|> instead of >|> >|> *p++ = *q++; >|> >|> but I actually *do* find the C representation easier/better etc. (perhaps >|> I'm wierd?) >Even if I like C, I think that this ++ is ugly and I'm glad that there isn't such >a thing in Ada. On the other hand what do you think about the operators += *= ... >They make thing shorter AND easier to read, a += 5; means exactly add 5 to a. >So don't you think that these construct have their place in Ada. 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. 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. 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); Any other thoughts? Nick Mellor Leeds