comp.lang.ada
 help / color / mirror / Atom feed
From: dmitry6243@my-deja.com
Subject: Re: Constructors/Destructors in Ada95
Date: Thu, 26 Oct 2000 11:44:44 GMT
Date: 2000-10-26T11:44:44+00:00	[thread overview]
Message-ID: <8t95fb$8s2$1@nnrp1.deja.com> (raw)
In-Reply-To: 8t6vhc$fmb$1@nnrp1.deja.com

In article <8t6vhc$fmb$1@nnrp1.deja.com>,
  mark.biggar@trustedsyslabs.com wrote:
> In article <8t6pi9$9s8$1@nnrp1.deja.com>,
>   dmitry6243@my-deja.com wrote:
> > In article <39F6D201.73C006FA@acm.org>,
> >   Marin David Condic <mcondic.nospam@acm.org> wrote:
> > > Ray Blaak wrote:
> > >
> > > > I really would like to be able to do:
> > > >
> > > >   procedure ":="(target : in out T; source : in T);
> > > >
> > > > so as to have complete control over what is happening. I vaguely
> recall some
> > > > rationale from the Ada 9X discussions for why user-defined
> assignment per se
> > > > was not incorporated. Does anyone remember?
> > >
> > > Does a
> > > statement like: "X < Y ;" make sense in Ada?) As a procedure,
you'd
> have to allow
> > > procedures to have symbol names - which opens up a whole can of
> worms. Further, it
> > > would mean allowing "infix procedures" which is hard to make sense
> of - or at least
> > > could make programs look really strange.
> >
> > It would be nice (it is in my private Ada to-do list for a long
time):
> >
> > function "*" (Left, Right : Matrix) return Matrix;  -- Produces a
new
> object
> > procedure "*" (Left : in out Matrix; Right : Matrix);  -- Multiplies
> Left to
> > Right "in-place"
> >
> > So I would count it as an advantage. There is another. If you have
> >
> > procedure ":="(target : in out T; source : in T);
> >
> > then your assignment may take a look on the left-side object before
> its
> > destruction. Ada's Adjust is much more (IMO too much) specialized.
> >
> > > I'm sure there are dozens of other reasons why it was decided not
to
> provide a
> > > means of letting the user define assignment. I'd think it would
> require perverting,
> > > warping and twisting language concepts too much.
> >
> > I think that the major reason was the decision to limit user defined
> > assigments by Controlled types. Doing so you must drop ":=" form,
> which
> > ontherwise would permanently remind you that actually all types
might
> be
> > assigned (:-))
>
> One of the problems with this proposal (redefineing ":=") is that
> you would have to define Initialize, Adjust and Finialize anyway
> as you need them to implement value parameter passing, temporary
> creation and function return values correctly.  Each of those is
> like assingment, but not exactly the same being, built out of the
> three primitives in different ways.

Yes. However, actually it is 5 primitives:

Allocator (System.Storage_Pools),
Default constructor (Initialize),
Copy constructor ("memmove" + Adjust),
Destructor (Finalize),
Deallocator (System.Storage_Pools)

> So it makes more sense to just
> define the three primitives and have the compiler generate
> standard usage sequences then to redefine ":=" and have strange
> and hard to understand things happen.

Most of programs are making strange and and hard to understand things
(:-)).

Yes. The compiler would generate the default assigment out of the
primitives and the programmer would override it if he were not satisfied
with the result.

There are lot of pitfalls here, but Initialize-Adjust-Finalize is
neither free of them. I had got a very nasty bug when a controlled type
was passed by copy instead of by reference as I thought (or better to
say, didn't care).

> There's a reason that C++ has several types of constructors and in
> many ways the Ada mechanism is simpler.

One needs at least two constructors, one for initialization, another for
creating temporal values (for instance, when an object is passed by
copy). We have this in Ada, we have this in C++.

I see nothing wrong if Ada would offer an ability to have initializing
constructors with parameters too. When

X : String (80);

is legal, why:

X : MyType (Y, Z, 3.1415);

cannot be allowed in addition to famous:

X : MyType := +(Y, Z, 3.1415); -- (:-))

User defined aggregates could also be a nice feature.

--
Regards,
Dmitry Kazakov


Sent via Deja.com http://www.deja.com/
Before you buy.



  reply	other threads:[~2000-10-26 11:44 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-10-18  0:00 Constructors/Destructors in Ada95 Francois Godme
2000-10-19  0:00 ` Marin David Condic
2000-10-19  0:00 ` tmoran
2000-10-19  0:00   ` Francois Godme
2000-10-19  0:00     ` Ted Dennison
2000-10-20  0:00     ` Tucker Taft
2000-10-20  0:00       ` Francois Godme
2000-10-21  0:00         ` Marin David Condic
2000-10-23  0:00       ` Francois Godme
2000-10-24  0:00         ` Ray Blaak
2000-10-25  0:00           ` Francois Godme
2000-10-25  0:00           ` Marin David Condic
2000-10-25  0:00             ` dmitry6243
2000-10-25  0:00               ` mark.biggar
2000-10-26 11:44                 ` dmitry6243 [this message]
2000-10-26 13:25                   ` Robert A Duff
2000-10-27  8:10                     ` dmitry6243
2000-10-26 17:55                   ` tmoran
2000-10-27  8:10                     ` dmitry6243
2000-10-26 21:31                 ` Tucker Taft
2000-10-27  8:46                   ` dmitry6243
2000-10-25  0:00               ` Pascal Obry
2000-10-26  0:00                 ` dmitry6243
2000-10-27  7:12             ` Ray Blaak
2000-10-27 18:11           ` Francois Godme
2000-10-30 11:36             ` Robert A Duff
2000-10-30 22:03               ` dale
2000-10-22  0:00     ` rwilson007007
2000-10-22  0:00       ` Francois Godme
2000-10-24  0:00         ` rwilson007007
2000-10-19  0:00 ` Ted Dennison
  -- strict thread matches above, loose matches on Subject: below --
2000-10-29 22:51 rwilson007007
2000-10-30  4:03 ` Ray Blaak
2000-10-30 12:13 ` Marin David Condic
2000-10-30 16:39   ` Randy Brukardt
replies disabled

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