Generics - Difference between ADA and Modula--3 
Author Message
 Generics - Difference between ADA and Modula--3

Hey, I having trouble figuring out all the differences between modula and
ada's implemenation of generics.... anyone got any insight or could send me
in the right direction?

Thank.
-John



Sat, 19 Jul 2003 12:48:02 GMT  
 Generics - Difference between ADA and Modula--3

Quote:

>Hey, I having trouble figuring out all the differences between modula and
>ada's implemenation of generics.... anyone got any insight or could send me
>in the right direction?

General comparison between Modula-3 and Ada would be interesting,
actually. (-:

-- Mark



Sun, 20 Jul 2003 00:04:12 GMT  
 Generics - Difference between ADA and Modula--3

Quote:


>>Hey, I having trouble figuring out all the differences between modula and
>>ada's implemenation of generics.... anyone got any insight or could send me
>>in the right direction?

>General comparison between Modula-3 and Ada would be interesting,
>actually. (-:

Like what? I can give a short overview, but I'm not sure it will
be helpful.

Modula-3 is designed to be garbage-collected, and provides controls to
handle stuff without garbage-collections.
Ada is designed so that it is possible to garbage-collect it. It's
only garbage-collected on the JVM's, which don't give you any control.
If there was another GC implementation, any garbage-collection control
would be implementation-specific.

Ada designers made perfectly type-safe generics. Modula-3 designers looked
at Ada generics and C++ templates and decided the Ada generics were too much
of a PITA and went with a C++-style design that catches mistakes at link-time
rather than compile-time.

Modula-3 enforces information-hiding by putting what would be in Ada's
private section into the body, at the cost of doing everything through
pointers (implementation detail.)

I don't believe Modula-3 has operator overloading.

Modula-3 compares types by value instead of by name, and introduces brands
to compensate for that.

Modula-3 has sets, whereas Ada's designers decided that packed arrays of
boolean sufficed.

Modula-3 unifies a lot of stuff under expections (like loop-exits and returns)
for (IMO) little gain and more confusion.

Modula-3 (proper) has a very minimal library, with huge "implementation
specific" additions (not a big deal, since every existing implementation
derives from the DEC one and shares those additions.) Ada has a decent size
library, with moderate additions provided by most implementors that are
usually implementation specific in practice as well as theory.

Modula-3 tried for a goal of a 50 page standard, and (IMO) ended up cramming
a larger language into 50 pages, with the resulting ambigiuties. While the
Ada standard is more readable than most, it is more formal and less ambigious
than the M3 one.

--

Pointless website: http://dvdeug.dhis.org



Wed, 23 Jul 2003 02:35:57 GMT  
 Generics - Difference between ADA and Modula--3

(snip)

Quote:
>Like what? I can give a short overview, but I'm not sure it will

I don't yet know enough about Ada to say. (-:

Quote:
>be helpful.
>Modula-3 is designed to be garbage-collected, and provides controls to
>handle stuff without garbage-collections.
>Ada is designed so that it is possible to garbage-collect it. It's
>only garbage-collected on the JVM's, which don't give you any control.
>If there was another GC implementation, any garbage-collection control
>would be implementation-specific.

That's a pity. So, there aren't any Ada compilers that compile to
native code and offer a runtime with decent GC? Are there any other
special tricks used to make memory management easier than, say, a C
programmer might expect?

Quote:
>Ada designers made perfectly type-safe generics. Modula-3 designers looked
>at Ada generics and C++ templates and decided the Ada generics were too much
>of a PITA and went with a C++-style design that catches mistakes at link-time
>rather than compile-time.

I'm not a big fan of how Modula-3's generics work, certainly.

(snip)

Quote:
>I don't believe Modula-3 has operator overloading.

It doesn't, except for the obvious built-in things like '+'.

Quote:
>Modula-3 compares types by value instead of by name, and introduces brands
>to compensate for that.

Yes. I prefer name-equivalence personally, so I brand a lot.

(snip interesting stuff)

Thanks! That was indeed helpful, believe it or not. (-:

-- Mark



Sat, 26 Jul 2003 04:51:30 GMT  
 Generics - Difference between ADA and Modula--3

Quote:


>>Ada is designed so that it is possible to garbage-collect it. It's
>>only garbage-collected on the JVM's, which don't give you any control.
>>If there was another GC implementation, any garbage-collection control
>>would be implementation-specific.

>That's a pity. So, there aren't any Ada compilers that compile to
>native code and offer a runtime with decent GC?

Not that I've heard of. I hacked the Boehm-Weiser GC into GNAT's runtime,
but GNAT uses some funky virtual base system that makes it crash when
running under a garbage collector. I may find the time to do it properly
(multilib it, in GCC terms), but at the very least that's going to wait
until a version of GNAT depending on the GCC 3.0 build technology comes
out.

Quote:
>Are there any other
>special tricks used to make memory management easier than, say, a C
>programmer might expect?

Ada's fairly flexible about stack usage. Occasionally you'll see something
like

for I in 1 .. 50 loop
        declare
                A: array (0 .. I) of Integer;
        begin
                ...
        end;
end loop;

where there's a varying array. Or alternately:

type bob is array (integer range <>) of foo;
...
while (complex_condition) loop
        declare
                Token: bob := Something_Returning_A_Varying_String;
        begin
                ...
        end;
end loop;

where you return a varying array. It doesn't catch a lot of stuff that
really needs garbage collection, but it catches some of the places where
a C program might leak memory.

--

Pointless website: http://dvdeug.dhis.org
"I don't care if Bill personally has my name and reads my email and
laughs at me. In fact, I'd be rather honored." - Joseph_Greg



Sat, 26 Jul 2003 05:46:45 GMT  
 Generics - Difference between ADA and Modula--3

Quote:


> (snip)
> >Like what? I can give a short overview, but I'm not sure it will

> I don't yet know enough about Ada to say. (-:

> >be helpful.

> >Modula-3 is designed to be garbage-collected, and provides controls to
> >handle stuff without garbage-collections.
> >Ada is designed so that it is possible to garbage-collect it. It's
> >only garbage-collected on the JVM's, which don't give you any control.
> >If there was another GC implementation, any garbage-collection control
> >would be implementation-specific.

> That's a pity. So, there aren't any Ada compilers that compile to
> native code and offer a runtime with decent GC?

IIRC, GNAT works with Boehm's GC, and I'm told by a former insider that the
Aonix implementation works with a third-party GC product.  I've never done
either.

Quote:
> Are there any other
> special tricks used to make memory management easier than, say, a C
> programmer might expect?

Some are built into the language (e.g., you never have to worry about
alignment of allocated values, unlike what one *should* do with C) and some
are available hooks, like user-defined allocators that can provide
predictable behaviour.  But overall, things work at a more abstract, safe
level.  For example, access values are always meaningful unless you
explicitly (and clearly) mess up.

---
Patrick Rogers                       Consulting and Training in:
http://www.classwide.com        Real-Time/OO Languages

(281)648-3165                          Software Fault Tolerance



Sat, 26 Jul 2003 06:46:18 GMT  
 Generics - Difference between ADA and Modula--3


Quote:

> >General comparison between Modula-3 and Ada would be interesting,
> >actually. (-:

> Like what? I can give a short overview, but I'm not sure it will
> be helpful.

It's helpful to me, since I don't know Modula-3 at all :-)

Quote:
>[...]
> Ada designers made perfectly type-safe generics. Modula-3 designers looked
> at Ada generics and C++ templates and decided the Ada generics were too
much
> of a PITA and went with a C++-style design that catches mistakes at
link-time
> rather than compile-time.

Oh yeah... link-time errors, no pain there... :-)

Quote:
> [...]
> Modula-3 compares types by value instead of by name, and introduces brands
> to compensate for that.

What does this mean?  Can you explain this one some more?

Thanks,
Mark



Sat, 26 Jul 2003 07:12:20 GMT  
 Generics - Difference between ADA and Modula--3

Quote:

> for I in 1 .. 50 loop
>         declare
>                 A: array (0 .. I) of Integer;
>         begin
>                 ...
>         end;
> end loop;

> where there's a varying array. Or alternately:

> type bob is array (integer range <>) of foo;
> ...
> while (complex_condition) loop
>         declare
>                 Token: bob := Something_Returning_A_Varying_String;
>         begin
>                 ...
>         end;
> end loop;

A very common version of this is

declare
   S : String := PragmARC.Get_Line;
begin
...

(Shameless plug: see the PragmAda Reusable Components at

http://home.earthlink.net/~jrcarter010/pragmarc.htm

).

S may be from zero to Positive'Last characters long. In Ada, you only
really need explicit memory allocation and deallocation for things like
unbounded dynamic data structures, such as linked lists. In C you need
them whenever the size of something is not known at compile time.

It should also be noted that controlled types can be used for automatic
deallocation of explicitly allocated memory, getting much of the
advantage of garbage collection with the predictable run times of manual
memory management.

--
Jeff Carter
"Go and boil your bottoms."
Monty python & the Holy Grail



Sat, 26 Jul 2003 08:36:43 GMT  
 Generics - Difference between ADA and Modula--3

Quote:

>> Modula-3 compares types by value instead of by name, and introduces brands
>> to compensate for that.

>What does this mean?  Can you explain this one some more?

type A is {Alpha, Beta, Gamma};
type B is {Alpha, Beta, Gamma};
type C is access A;
type D is access B;
type E is branded access A;
type F is branded access A;

In Ada, A, B, C, D, E and F are different types. In Modula 3, A & B are
the same type (because they have the same expanded form), and C & D are
the same type. However, E and F are distinct from each other and C and D,
because of the brands.

--

Pointless website: http://dvdeug.dhis.org
"I don't care if Bill personally has my name and reads my email and
laughs at me. In fact, I'd be rather honored." - Joseph_Greg



Sat, 26 Jul 2003 07:50:53 GMT  
 Generics - Difference between ADA and Modula--3

Quote:

>> Ada designers made perfectly type-safe generics. Modula-3 designers looked
>> at Ada generics and C++ templates and decided the Ada generics were too
>much
>> of a PITA and went with a C++-style design that catches mistakes at
>link-time
>> rather than compile-time.

>Oh yeah... link-time errors, no pain there... :-)

Quote from language reference introduction (which explains the why and how
of many Modula-3 features):

| In the same spirit of simplicity, there is no separate typechecking
| associated with generics. Implementations are expected to expand the
| generic and typecheck the result. The alternative would be to invent
| a polymorphic type system flexible enough to express the constraints
| on the parameter interfaces that are necessary in order for the generic
| body to compile. This has been achieved for ML and CLU, but it has not
| yet been achieved satisfactorily in the Algol family of languages,
| where the type systems are less uniform. (The rules associated with
| Ada generics are too complicated for our taste.)

(Note that this document was written prior to Ada 95.)
The Introduction (http://www.research.compaq.com/SRC/m3defn/html/intro.html)
is an interesting look at the design of a "Algol family" (i.e. Ada, Oberon,
the Modula's, Java) and some of the choices that could be made.

--

Pointless website: http://dvdeug.dhis.org
"I don't care if Bill personally has my name and reads my email and
laughs at me. In fact, I'd be rather honored." - Joseph_Greg



Sat, 26 Jul 2003 08:03:55 GMT  
 Generics - Difference between ADA and Modula--3

Quote:

> These days I heavily use pointers in native Ada, because I have a fixed
> Storage_Array which needs to be reinterpreted by different record types.

Why not try something like this:
  X : array (1..Zillions) of Byte;
  Y : Magic_Record;
  for Y'Address use X'Address;  -- remember about alignment, too!

-----------------------------------------------------------------

 Senior Lecturer           | http://www.it.bton.ac.uk/staff/je
 Dept. of Computing        | ** NON-PROFIT CD FOR CS STUDENTS **
 University of Brighton    |    -- see http://burks.bton.ac.uk
-----------------------------------------------------------------



Sun, 27 Jul 2003 21:10:48 GMT  
 Generics - Difference between ADA and Modula--3

Quote:

> > I would have much preferred a rule that allowed arrays of classwide
> > objects, but handled them something like the ways arrays of variant
> > records are currently treated.

> Ted, with variant records, you know the maximum size, and this is what
> is allocated for arrays of unconstrained variant records.
> For tagged types, you do not know the maximum size.

At link time you could figure that out since by then all the sizes of
all the types in the class are known, but that is perhaps too much work.
It'd be nice for the users if it could be done, but I'd think it would
require a custom linker for Ada programs. Since a lot of compilers rely
on common C linkers, I don't think such a solution would be deemed
acceptable by vendors.

However, that's for *constained* variant record (sub)types. (Perhaps I'm
using the wrong terminology.) What I was talking about was that for an
unconstrained variant record type, the declaration of an object must
have some kind of initializer specifying the variants being used (and
thus the size). Thereafter the variant can't be changed, although the
other fields can. That would still not get rid of every instance where
pointers are needed, as you'd have to be able to live with an array
where you are unable to change the components too drasticly.

Right now, variant record types and other "indefinite subtypes" may not
be used in arrays. However, let's say for a moment that they could be.
Such an array would have to have the following restrictions:

   o  Any objects declared of this array's type would have to have an
initializer so that all the array elements would be constrained.
   o  Assignments to elements in the array could not change the variants.

If we then extend this hypothetical array rule to tagged types, you can
just replace "variants" with "tag" in the above, and things should work out.

Now that I type this out though, the argument is starting to look quite
familiar. If I remember right, the problem with it is that making array
elements take up different physical sizes blows simple array indexing
out of the water. You'd have to index into it by walking through the
array one element at a time. Since this is the same work as traversing a
linked-list, you might as well just use a linked-list for this purpose
and be done with it.

Clearly better minds than mine have already been over this. If a
solution was easy enough that *I* could figure it out, we wouldn't be in
this pickle in the first place. :-)

--
T.E.D.

http://www.telepath.com/~dennison/Ted/TED.html

Sent via Deja.com
http://www.deja.com/



Sun, 27 Jul 2003 22:52:12 GMT  
 Generics - Difference between ADA and Modula--3
I appreciate everyone's comments in this thread. It's been quite
illuminating.

-- Mark



Sat, 02 Aug 2003 04:38:38 GMT  
 
 [ 13 post ] 

 Relevant Pages 

1. Modula-2 to Ada translator written in Modula-2 or C

2. generics defined in terms of generics?

3. generics using generics (long)

4. Difference between Ada 83 and Ada 95

5. Ada 95 version Ada.... What is the differences

6. Inheritance and Ada (and access types and generics)

7. Ada '0x generics brain-fartz (long)

8. Ada Generics vs. C++ templates

9. Ada generics are bad

10. Ada generics / GNAT Heap-sort

11. Ada generics, numerics, and conversions

12. Generics and Ada Compiler Validation

 

 
Powered by phpBB® Forum Software