comp.lang.ada
 help / color / mirror / Atom feed
* Generics - Difference between ADA and Modula--3
@ 2001-01-30  4:48 John Baltomoire
  2001-01-30 16:04 ` Mark Carroll
  0 siblings, 1 reply; 13+ messages in thread
From: John Baltomoire @ 2001-01-30  4:48 UTC (permalink / raw)


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





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

* Re: Generics - Difference between ADA and Modula--3
  2001-01-30  4:48 Generics - Difference between ADA and Modula--3 John Baltomoire
@ 2001-01-30 16:04 ` Mark Carroll
  2001-02-02 18:35   ` David Starner
  0 siblings, 1 reply; 13+ messages in thread
From: Mark Carroll @ 2001-01-30 16:04 UTC (permalink / raw)


In article <3a7646fb$1@rsl2.rslnet.net>,
John Baltomoire <bfaws@REMOVEDISiname.com> wrote:
>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



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

* Re: Generics - Difference between ADA and Modula--3
  2001-01-30 16:04 ` Mark Carroll
@ 2001-02-02 18:35   ` David Starner
  2001-02-05 20:51     ` Mark Carroll
  2001-02-05 23:12     ` Mark Lundquist
  0 siblings, 2 replies; 13+ messages in thread
From: David Starner @ 2001-02-02 18:35 UTC (permalink / raw)


On 30 Jan 2001 16:04:12 GMT, Mark Carroll <carroll@cis.ohio-state.edu> wrote:
>In article <3a7646fb$1@rsl2.rslnet.net>,
>John Baltomoire <bfaws@REMOVEDISiname.com> wrote:
>>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.

-- 
David Starner - dstarner98@aasaa.ofe.org
Pointless website: http://dvdeug.dhis.org



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

* Re: Generics - Difference between ADA and Modula--3
  2001-02-02 18:35   ` David Starner
@ 2001-02-05 20:51     ` Mark Carroll
  2001-02-05 21:46       ` David Starner
                         ` (3 more replies)
  2001-02-05 23:12     ` Mark Lundquist
  1 sibling, 4 replies; 13+ messages in thread
From: Mark Carroll @ 2001-02-05 20:51 UTC (permalink / raw)


In article <95eumd$8i41@news.cis.okstate.edu>,
David Starner <dstarner98@aasaa.ofe.org> wrote:
(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? Are there any other
special tricks used to make memory management easier than, say, a C
programmer might expect?

>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)
>I don't believe Modula-3 has operator overloading.

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

>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



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

* Re: Generics - Difference between ADA and Modula--3
  2001-02-05 20:51     ` Mark Carroll
@ 2001-02-05 21:46       ` David Starner
  2001-02-06  0:36         ` Jeffrey Carter
  2001-02-05 22:46       ` Pat Rogers
                         ` (2 subsequent siblings)
  3 siblings, 1 reply; 13+ messages in thread
From: David Starner @ 2001-02-05 21:46 UTC (permalink / raw)


On 5 Feb 2001 20:51:30 GMT, Mark Carroll <carroll@cis.ohio-state.edu> wrote:
>In article <95eumd$8i41@news.cis.okstate.edu>,
>David Starner <dstarner98@aasaa.ofe.org> wrote:
>
>>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.

>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.

-- 
David Starner - dstarner98@aasaa.ofe.org
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



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

* Re: Generics - Difference between ADA and Modula--3
  2001-02-05 20:51     ` Mark Carroll
  2001-02-05 21:46       ` David Starner
@ 2001-02-05 22:46       ` Pat Rogers
       [not found]       ` <95p1p7$3s9$1@nnrp1.deja.com>
  2001-02-12 20:38       ` Mark Carroll
  3 siblings, 0 replies; 13+ messages in thread
From: Pat Rogers @ 2001-02-05 22:46 UTC (permalink / raw)


"Mark Carroll" <carroll@cis.ohio-state.edu> wrote in message
news:95n3oi$5nh$1@news.cis.ohio-state.edu...
> In article <95eumd$8i41@news.cis.okstate.edu>,
> David Starner <dstarner98@aasaa.ofe.org> wrote:
> (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.

> 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
progers@classwide.com          Hard Deadline Schedulability Analysis
(281)648-3165                          Software Fault Tolerance





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

* Re: Generics - Difference between ADA and Modula--3
  2001-02-02 18:35   ` David Starner
  2001-02-05 20:51     ` Mark Carroll
@ 2001-02-05 23:12     ` Mark Lundquist
  2001-02-05 23:50       ` David Starner
  2001-02-06  0:03       ` David Starner
  1 sibling, 2 replies; 13+ messages in thread
From: Mark Lundquist @ 2001-02-05 23:12 UTC (permalink / raw)



David Starner <dvdeug@x8b4e53cd.dhcp.okstate.edu> wrote in message
news:95eumd$8i41@news.cis.okstate.edu...
> >
> >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 :-)

>[...]
> 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... :-)

> [...]
> 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






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

* Re: Generics - Difference between ADA and Modula--3
  2001-02-05 23:12     ` Mark Lundquist
@ 2001-02-05 23:50       ` David Starner
  2001-02-06  0:03       ` David Starner
  1 sibling, 0 replies; 13+ messages in thread
From: David Starner @ 2001-02-05 23:50 UTC (permalink / raw)


On Mon, 5 Feb 2001 15:12:20 -0800, Mark Lundquist <mark@rational.com> wrote:
>> 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.

-- 
David Starner - dstarner98@aasaa.ofe.org
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



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

* Re: Generics - Difference between ADA and Modula--3
  2001-02-05 23:12     ` Mark Lundquist
  2001-02-05 23:50       ` David Starner
@ 2001-02-06  0:03       ` David Starner
  1 sibling, 0 replies; 13+ messages in thread
From: David Starner @ 2001-02-06  0:03 UTC (permalink / raw)


On Mon, 5 Feb 2001 15:12:20 -0800, Mark Lundquist <mark@rational.com> wrote:
>> 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.

-- 
David Starner - dstarner98@aasaa.ofe.org
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



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

* Re: Generics - Difference between ADA and Modula--3
  2001-02-05 21:46       ` David Starner
@ 2001-02-06  0:36         ` Jeffrey Carter
  0 siblings, 0 replies; 13+ messages in thread
From: Jeffrey Carter @ 2001-02-06  0:36 UTC (permalink / raw)


David Starner wrote:
> 
> 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



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

* Re: Generics - Difference between ADA and Modula--3
       [not found]         ` <slrn98049v.155.lutz@taranis.iks-jena.de>
@ 2001-02-07 13:10           ` John English
  0 siblings, 0 replies; 13+ messages in thread
From: John English @ 2001-02-07 13:10 UTC (permalink / raw)


Lutz Donnerhacke wrote:
> 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!

-----------------------------------------------------------------
 John English              | mailto:je@brighton.ac.uk
 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
-----------------------------------------------------------------



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

* Re: Generics - Difference between ADA and Modula--3
       [not found] <mailman.981529807.716.comp.lang.ada@ada.eu.org>
@ 2001-02-07 14:52 ` Ted Dennison
  0 siblings, 0 replies; 13+ messages in thread
From: Ted Dennison @ 2001-02-07 14:52 UTC (permalink / raw)


In article <mailman.981529807.716.comp.lang.ada@ada.eu.org>,
  comp.lang.ada@ada.eu.org wrote:
> > 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/



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

* Re: Generics - Difference between ADA and Modula--3
  2001-02-05 20:51     ` Mark Carroll
                         ` (2 preceding siblings ...)
       [not found]       ` <95p1p7$3s9$1@nnrp1.deja.com>
@ 2001-02-12 20:38       ` Mark Carroll
  3 siblings, 0 replies; 13+ messages in thread
From: Mark Carroll @ 2001-02-12 20:38 UTC (permalink / raw)


I appreciate everyone's comments in this thread. It's been quite
illuminating.

-- Mark



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

end of thread, other threads:[~2001-02-12 20:38 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-01-30  4:48 Generics - Difference between ADA and Modula--3 John Baltomoire
2001-01-30 16:04 ` Mark Carroll
2001-02-02 18:35   ` David Starner
2001-02-05 20:51     ` Mark Carroll
2001-02-05 21:46       ` David Starner
2001-02-06  0:36         ` Jeffrey Carter
2001-02-05 22:46       ` Pat Rogers
     [not found]       ` <95p1p7$3s9$1@nnrp1.deja.com>
     [not found]         ` <slrn98049v.155.lutz@taranis.iks-jena.de>
2001-02-07 13:10           ` John English
2001-02-12 20:38       ` Mark Carroll
2001-02-05 23:12     ` Mark Lundquist
2001-02-05 23:50       ` David Starner
2001-02-06  0:03       ` David Starner
     [not found] <mailman.981529807.716.comp.lang.ada@ada.eu.org>
2001-02-07 14:52 ` Ted Dennison

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