comp.lang.ada
 help / color / mirror / Atom feed
* Re: how to do this in Ada?
@ 1990-03-13 18:56 westley
  1990-03-15 16:11 ` Thomas Vachuska
  1990-03-15 16:40 ` RCAPENER
  0 siblings, 2 replies; 3+ messages in thread
From: westley @ 1990-03-13 18:56 UTC (permalink / raw)


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;
>    }
>
>See how I left out the breaks on purpose.
>
>In ADA you wouldn't be able to do this without duplicating either the
>case-expression (they aren't always simple numbers) or the statements.
>

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.

Algorithm and data structure design (and ease of expression thereof) are
much more important to the development and maintenance of good software
than this kind of concern for what language is better for low-level
efficiency.  Personally, I find Ada to be especially good for this (and
yes, I have used C extensively).  Your mileage may vary.

---------------- Different topic follows: -------------------------

Now, for an Ada topic I have been struggling with and would love to hear
advice from those who have done the equivalent in Ada.  I don't want to
hear from those who tell me to do it in C.

We are building a real-time radar simulation on a distributed network of
~35 Sun workstations and ~35 68030 CPU boards (Motorola MVME147
specifically).  Parts of the network will be Ethernet; the backbone will
be FDDI.  Now, for my question:

I have approximately 200 unique messages that are transmitted over the
net among all the various nodes.  How do I send a particular Ada object
of some arbitrary record type to another node while:

1) preserving strong typing -- I don't want to have to convert
   everything to some common structure such as an array of bytes

2) reducing messages to the smallest possible size -- I need to reduce
   the net traffic as much as possible -- as you know, there are numerous
   challenges relating to using variant record structures while trying
   to achieve this goal

3) avoiding giving global visibility to all message types to all program
   units

I started out by writing a LAN interface package as a generic patterned
after sequential_io.  You instantiate it with the particular variant
record structure that applies to the sender and receiver of that
particular data.  I also imported a function to determine the size of
a particular record so that I wouldn't always be sending the maximum
size of the record.

The major problem with this is that I have many different combinations
of messages to be sent to each destination.  Here is a much simplified
example of this problem.  Suppose I have three elements that need to
communicate:

	Element #	Runs on Processor	Needs message types
	---------	----------------	-------------------
            1                  A                       a, b, c
            2                  B                       b, c
            3                  C                       a, c

I could build a variant record structure of message types a, b, and c.
However, then Element 2 and 3 have visibility to message types they have
no business seeing.  I can't build three variant records (a-b-c, b-c,
and a-c) because the record types will now be incompatible.

Any ideas?

Terry J. Westley
Arvin/Calspan Advanced Technology Center
P.O. Box 400, Buffalo, NY 14225
acsu.buffalo.edu!planck!westley@hercules


Terry J. Westley
Arvin/Calspan Advanced Technology Center
P.O. Box 400, Buffalo, NY 14225
acsu.buffalo.edu!planck!westley@hercules

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Re: how to do this in Ada?
  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
  1 sibling, 0 replies; 3+ messages in thread
From: Thomas Vachuska @ 1990-03-15 16:11 UTC (permalink / raw)



    I had a very similar problem, but I chose the dirty way of converting
the records to byte arrays and then sending them.  One advantage of doing it 
this way is that one can perform 'checksum' operation on the byte array to
assure proper delivery, but otherwise this approach (as you mentioned) 
completely bypasses the type checking guards and is not very robust.

    I would be very interested in finding out how one can solve this 
problem (in Ada of course) a bit more elegantly.

Thanks


Thomas Vachuska

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: how to do this in Ada?
  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
  1 sibling, 0 replies; 3+ messages in thread
From: RCAPENER @ 1990-03-15 16:40 UTC (permalink / raw)


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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~1990-03-15 16:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox