comp.lang.ada
 help / color / mirror / Atom feed
From: Martin Krischik <krischik@users.sourceforge.net>
Subject: Re: 'Base
Date: Sat, 10 Dec 2005 08:52:45 +0100
Date: 2005-12-10T08:52:45+01:00	[thread overview]
Message-ID: <1170126.PvJVGQkA4J@linux1.krischik.com> (raw)
In-Reply-To: 1134160956.403383.29180@z14g2000cwz.googlegroups.com

ada_student@yahoo.com wrote:

> Indefinite subtypes cannot be allowed under any circumstances.
> It sounds like a hack just inorder to allow one class of array
> object declarations into the language.

No at all. Ada is a higher level language then C/C++ or Java. It allows for
better abstraction  which is closer to real live. In real live arrays
seldom beginn with zero:

Weekdays 1 .. 7
Month 1 .. 31
Year 1 .. 366

Ada allows integer and array type for all those circumstances.

> How can a statically typed language allow a type whose size is not
> known at compile time?

Quite easily. The size is just calculated at run time and the memory needed
is then allocated staticly, on stack or on heap. The actual size becomes
part of the array itself.

In lower level languages this tedious work is dumped onto the programmer. 

> The Java array type certainly wins over Ada in this regard.

Really? How about:

type Historic_Data is array (-6000 .. 2005) of Data_Entry;

Java (and C/C++) only have zero based arrays. In my eye that allway looses
over abritary array bound. "Off by one error" is a well known term in those
languages. 

To represent an Ada array in Java you would need:

class Array_Type
   {
   private int First;
   private int Last;
   private Data Elements [];

   Data get_Element (int Index)
     {
     if (Index > First) then throw ....
     if (Index < Last) then throw ....
     return Data [Index - First];
     } 
   }

Ada arrays are not a primitive type - they are a quite complex and powerfull
type.

Performace? Ada allways outperform Java for a start. But Ada's build in
checks will also outperform C/C++ when used with all appropriate
"assert()"s in place.

For details on why read:

http://en.wikibooks.org/wiki/Computer_programming/Error_handling
http://en.wikibooks.org/wiki/Ada_Programming/Error_handling

Especially chapter 5 on "Design by Contract".

Martin
-- 
mailto://krischik@users.sourceforge.net
Ada programming at: http://ada.krischik.com



  parent reply	other threads:[~2005-12-10  7:52 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-12-08 15:21 'Base ada_student
2005-12-08 18:08 ` 'Base Matthew Heaney
2005-12-08 18:44   ` 'Base Martin Dowie
2005-12-08 18:49     ` 'Base Martin Dowie
2005-12-08 19:24     ` 'Base Matthew Heaney
2005-12-08 20:27       ` 'Base Martin Dowie
2005-12-08 19:51     ` 'Base Jeffrey R. Carter
2005-12-08 20:07       ` 'Base Matthew Heaney
2005-12-09  2:57         ` 'Base Randy Brukardt
2005-12-09  2:13   ` Avoiding constraint checks w/ 'Base Anonymous Coward
2005-12-09  3:11     ` Randy Brukardt
2005-12-09 13:11   ` 'Base krischik
2005-12-09 13:52     ` 'Base Matthew Heaney
2005-12-09 20:42       ` 'Base Randy Brukardt
2005-12-08 19:11 ` 'Base Martin Krischik
2005-12-09 20:42   ` 'Base ada_student
2005-12-09 21:39     ` 'Base Pascal Obry
2005-12-10  3:30     ` 'Base Matthew Heaney
2005-12-10 14:50       ` 'Base ada_student
2005-12-10  7:52     ` Martin Krischik [this message]
2005-12-10 12:55       ` 'Base Larry Kilgallen
2005-12-10 13:37         ` 'Base Björn Persson
2005-12-11 11:00           ` 'Base Martin Krischik
2005-12-10 15:01         ` 'Base Robert A Duff
2005-12-11 10:59         ` 'Base Martin Krischik
2005-12-12  9:14       ` 'Base Ole-Hjalmar Kristensen
2005-12-12 19:08         ` 'Base Martin Krischik
2005-12-13 19:24           ` 'Base tmoran
2005-12-13 21:00         ` 'Base Georg Bauhaus
2005-12-14 19:43         ` 'Base Per Sandberg
2005-12-15 20:08           ` 'Base Martin Krischik
2005-12-16 19:19             ` 'Base Jeffrey R. Carter
2005-12-17  7:52               ` 'Base Martin Krischik
replies disabled

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