From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: * X-Spam-Status: No, score=1.8 required=3.0 tests=BAYES_50,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.5-pre1 Path: eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.ada Subject: Re: Ada syntax questions Date: Sun, 20 Dec 2020 13:59:20 -0800 Organization: None to speak of Message-ID: <87r1nkb0lj.fsf@nosuchdomain.example.com> References: <5fdbde31$0$6455$426a74cc@news.free.fr> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: reader02.eternal-september.org; posting-host="9f490a3b8ea0115c181f7feedac4ea30"; logging-data="27297"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18MwRdPJCSVIe1vrc8FdWdg" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) Cancel-Lock: sha1:XP48xLuf0X6YPom35FUwYFmTRVU= sha1:C5KGl1WdElRxsxiUEfvvth+qIMU= Xref: reader02.eternal-september.org comp.lang.ada:60903 List-Id: Niklas Holsti writes: > On 2020-12-18 0:39, DrPi wrote: >> Ada claims to have a better syntax than other languages. > > I would say the claim is that the Ada syntax was rationally designed > to have certain properties, which are desired by certain users (us Ada > programmers) so it is "better" for us, although some aspects are > subjective for sure. > > In addition to what others have said, here are some further comments > on the examples you gave: > >> 1) What about array indexing ? >> In some other languages, arrays are indexed using square >> brackets. In Ada, parentheses are used for function calls and for >> array indexing. I've never found any of the arguments in favor of using parentheses for array indexing convincing, and I've never liked the way Ada does it. But of course the decision was made in the early 1980s, and it can't be changed now. At least part of the reason was that Ada needed to be used on systems that didn't have '[' and ']' in their character sets. I don't know to what extent that necessity has been used as an after the fact rationalization. Function calls and array indexing can be substituted for one another in *some* circumstances, but not it all. But they really are very different things. A function call executes user-written code, and may have side effects; an array indexing expression refers to an object. An array indexing expression can appear on the LHS of an assignment; a function call can't. If Ada had originally used '[' and ']' for array indexing, I doubt that anyone would be complaining that it would have been better to use '(' and ')' (other than some Fortran programmers, I suppose). Why not use parentheses for record components, Object(Component) rather than Object.Component? Doesn't the same argument apply? > There are proposals to allow [] as well as (), mainly to increase > familiarity for new Ada users. Ick. The only thing more confusing than using () for array indexing would be allowing either () or [] at the programmer's whim. (Well, not the only thing; I'm sure I could come up with something even worse.) >> 2) In Ada, a function without arguments is called without any parentheses. > > Parameterless functions are rare, and properly so. > > Parameterless procedures are much more common. Writing > > Frobnicate_Widget(); > > is longer than > > Frobnicate_Widget; > > and seems to have no advantages over the shorter form. I wouldn't have expected the designers of Ada to be concerned about saving two characters. I see your point about procedure calls. A statement consisting of an identifier followed by a semicolon can only be a procedure call (I think), so there's no ambiguity. My mild dislike for the function call syntax is that it needlessly treats the zero-parameter case as special. There could also be some potential ambiguities, though I'm not aware of any actual ambiguous cases in Ada. In some languages, the name of a function not followed by parentheses refers to the function itself (or its address) and does not call it. I can easily imagine an attribute for which Func'Attribute could sensibly refer either to the function Func itself or to the value returned by calling it. Again, if Ada 83 had required empty parentheses on parameterless procedure and function calls, I'm skeptical that anyone would now be arguing that it was a bad decision. And again, it would be impossible to change it without breaking existing code. -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com Working, but not speaking, for Philips Healthcare void Void(void) { Void(); } /* The recursive call of the void */