comp.lang.ada
 help / color / mirror / Atom feed
From: RCAPENER@cc.utah.edu
Subject: Re: how to do this in Ada?
Date: 15 Mar 90 16:40:00 GMT	[thread overview]
Message-ID: <51041@cc.utah.edu> (raw)
In-Reply-To: 1990Mar13.185638.16143@planck.uucp

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

  parent reply	other threads:[~1990-03-15 16:40 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1990-03-13 18:56 how to do this in Ada? westley
1990-03-15 16:11 ` Thomas Vachuska
1990-03-15 16:40 ` RCAPENER [this message]
  -- strict thread matches above, loose matches on Subject: below --
1990-03-18  3:23 Gary Morris
1990-03-19 17:11 ` C.E. Thompson
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox