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 Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!cs.utexas.edu!hellgate.utah.edu!cc.utah.edu!rcapener From: RCAPENER@cc.utah.edu Newsgroups: comp.lang.ada Subject: Re: how to do this in Ada? Message-ID: <51041@cc.utah.edu> Date: 15 Mar 90 16:40:00 GMT References: <1990Mar13.185638.16143@planck.uucp> Followup-To: comp.lang.ada List-Id: In article <1990Mar13.185638.16143@planck.uucp>, westley@hercules.uucp writes: > With apologies to those of you who already saw this in > comp.software-eng -- I didn't edit the newsgroup header properly and > wanted this to go into comp.lang.ada: > > In article <1771@awdprime.UUCP> sanders@sanders.austin.ibm.com (Tony Sanders) writes: >>How do you do this in ADA? >> >> switch(n) { >> case 0: >> count++; >> case 1: >> ocount++; >> case 2: >> printf("%d %d\n",count,ocount); >> break; >> default: >> printf("unknown n\n"); >> break; >> } >> > > If the code is short enough that I can easily see any errors, I *would* > duplicate it; if its not, I'd use a subprogram. In either case, we are > talking about micro-efficiency here. > No you wouldn't, and that's because Ada doesn't fall through in the case statement like C does. Here is how you would really do it. >> switch(n) { >> case 0: >> count++; >> case 1: >> ocount++; >> case 2: >> printf("%d %d\n",count,ocount); >> break; >> default: >> printf("unknown n\n"); >> break; >> } if n = 0 then count := count + 1; end if; if n = 0 or n = 1 then ocount := ocount + 1; end if; if n = 0 or n = 1 or n = 2 then write... -- the equivalent here takes a few lines of code else write... -- ditto for this one end if; Lest you think this is necessarily going to generate more code, don't bet on it. The C may be clearer (personal opinion applies here), but both are going to generate about the same machine code, assuming that we are talking an optimizing Ada compiler that has been honed as long as the C compiler. Since I have nothing more to compare than VAX-VMS Ada and VAX-C, GNU C, or pcc to compare my observation is bound to be biased. From my perspective Ada is a real dog when speed of execution becomes an issue. Lest I be flamed, let me state that I like both C and Ada (prefer C most of the time). My only complaint is that for being as big as it is, Ada doesn't provide me with all the power of say, Common LISP! So let's stop flaming. If you like Ada and can find a job programming in it, by all means do so. The rest of us not working on DOD and other government projects have to get things done in the shortest amount of time possible, and it better run quick! Has anyone seen a good relational data base written in Ada instead of C? Don't flame RCAPENER! (I stole his account) flames to: dharvey@wsccs.weber.edu