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=-0.8 required=5.0 tests=BAYES_00,INVALID_DATE autolearn=no 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-23 12:46:31 PST Newsgroups: comp.lang.ada Path: nntp.gmd.de!newsserver.jvnc.net!nntpserver.pppl.gov!princeton!udel!gatech!willis.cis.uab.edu!news.ecn.bgu.edu!newspump.wustl.edu!fas-news.harvard.edu!das-news2.harvard.edu!cantaloupe.srv.cs.cmu.edu!bb3.andrew.cmu.edu!news.sei.cmu.edu!firth From: firth@sei.cmu.edu (Robert Firth) Subject: Re: "Subtract C, add Ada" Message-ID: <1995Jan23.154631.6702@sei.cmu.edu> Sender: netnews@sei.cmu.edu (Netnews) Organization: Software Engineering Institute References: <3fo2ot$su2@miranda.gmrc.gecm.com> Date: Mon, 23 Jan 1995 15:46:31 EST Date: 1995-01-23T15:46:31-05:00 List-Id: In article <3fo2ot$su2@miranda.gmrc.gecm.com> bill@valiant (R.A.L Williams) writes: I guess I'm about to show my ignorance of C, but I'm very confused bt this post. > 1. It allows your code to be more compact. > NB DONT confuse compactness with poor layout! I find that, for example: > > while ((c = getchar()) == ' ') > { > /* count spaces */ > } > > is clearer than the 'expanded' alternative (to *me* :-). Nope, I find this totally unclear. Who's counting? Unless I've missed an invisible declaration, initialisation, and increment, the above code *doesn't* count spaces, it skips them. And if that is its purpose, what's the point of the variable 'c'? Why not just say WHILE getchar = ASCII.SP LOOP null; END LOOP; Though, again, I'd much rather write this: LOOP get(c); EXIT WHEN c /= ASCII.SP; END LOOP; since the postcondition I almost certainly want to establish - that c holds the next non-space character - is written right there in the code. Note also that if there are *no more* non space characters, the C code dies in an infinite loop, while the Ada code automatically does the right thing, namely raises the END_ERROR exception. >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?) Again, I don't see it. The Ada code makes it clear that *corresponding* elements of the array Q are being copied into P - though, of course, a real Ada programmer (TM) would have written just P := Q. The C code doesn't make that clear - you're going to have to ferret out the initialisations of p and q to determine that. And if you worry about the correctness of the copy - for instance, whether P and Q are the same size - that's surely going to be a lot easier to establish in Ada.