From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Ada-Singleton-Why does it work like this?
Date: Fri, 27 Mar 2009 11:02:13 +0100
Date: 2009-03-27T11:02:13+01:00 [thread overview]
Message-ID: <18mv53mf50kqw$.1k3zsftqjzwk2$.dlg@40tude.net> (raw)
In-Reply-To: ea16a985-170f-44be-9e25-322f7da0ca2e@h28g2000yqd.googlegroups.com
On Thu, 26 Mar 2009 15:00:52 -0700 (PDT), Maciej Sobczak wrote:
> On 26 Mar, 15:28, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
> wrote:
>
>>> Can you defend the idea that creation does not belong to the type?
>>
>> I think I can. Creation cannot be expressed in terms of values of the type.
> [...]
>
> Makes sense.
> What about... constructors? I mean the real ones.
The real ones are magical things.
> In other mainstream languages (you know, those with curly braces ;-) )
> and let's say in Ada 2015 as well, constructors are defined
> *syntactically* within the type.
The "constructors" of C++ are not constructors, but user-defined procedures
called from the real constructor at certain stages of object construction.
It is similar to Ada.Finalization.Initialize, but far better designed.
(Except than unavoidable in C++ nonsense of the object type mutating during
construction.)
> If we consider the object creation as
> something that does not belong to the type, then can we say that
> having constructors in a type definition is just a convenient
> distortion and not a clear expression of the *semantic* reality, where
> constructor should be defined as the entity that is external to the
> type?
>
> Something like:
>
> class X
> {
> public:
> void doThis();
> void doThat();
> private:
> // ...
> };
>
> // imaginary constructor of type X
> X()
> {
> // make up the state of new object
> }
>
> What is "inside" or "outside" might have no sense in Ada, but in Ada
> terms the problem can be expressed as whether constructors should be
> primitive operations of the given type.
In my view neither the constructor nor the user-defined construction hook
are primitive operations in traditional sense. That is, a primitive
operation is defined on a class of types and its implementation has a
separate body for each type from the class. I.e. f acts on T'Class and for
each type S from the class T, there is a body S.f. This body is either
inherited and then composed with a type conversion (S.f = S_from_T o T.f o
T_from_S) or else is overridden by the user.
A user-defined construction hook of T is neither inherited by S, nor
overridden by the user. The "real constructor" of S calls the hook of T
upon construction of S before it does the hook of S. That is a different
way of procedural composition. It is additive. (Of course, when
constructing hook of T is called on S, S is first converted to T and then
back to S. This is a mere view conversion for by-reference types.)
We could imagine some generalized model of a primitive operation in which a
body of f for the type T would consist of some prologue, overridable part
and epilogue. A derived type S would be able to extend the prologue and/or
epilogue and to replace the overridable part. (This could be useful if you
wanted to do transaction or concurrent stuff transparently. For example,
the prologue could grab a lock, the epilogue would release it. The
overridable part would do things.)
However, even in this generalized model I would keep
constructing/destructing hooks separate from primitive operations in order
to prevent them called elsewhere than from compiler-generated constructors
and destructors. Just for safety reasons. C++ people did it right, when
they forbade explicit calls to T::T() and T::~T().
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
next prev parent reply other threads:[~2009-03-27 10:02 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-24 19:01 Ada-Singleton-Why does it work like this? patrick.gunia
2009-03-24 19:10 ` Pascal Obry
2009-03-24 20:47 ` Jeffrey R. Carter
2009-03-25 0:10 ` Martin
2009-03-25 0:41 ` Jeffrey R. Carter
2009-03-25 9:30 ` Dmitry A. Kazakov
2009-03-26 8:55 ` Martin
2009-03-26 9:28 ` Dmitry A. Kazakov
2009-03-26 13:39 ` Maciej Sobczak
2009-03-26 14:07 ` Georg Bauhaus
2009-03-26 14:33 ` Dmitry A. Kazakov
2009-03-26 15:22 ` Georg Bauhaus
2009-03-26 16:31 ` Dmitry A. Kazakov
2009-03-26 14:28 ` Dmitry A. Kazakov
2009-03-26 22:00 ` Maciej Sobczak
2009-03-27 10:02 ` Dmitry A. Kazakov [this message]
2009-03-25 22:29 ` sjw
2009-03-24 20:52 ` Ludovic Brenta
2009-03-25 9:59 ` patrick.gunia
2009-03-25 10:29 ` Jean-Pierre Rosen
2009-03-25 11:26 ` Georg Bauhaus
2009-03-25 11:49 ` patrick.gunia
2009-03-29 7:29 ` Jacob Sparre Andersen
2009-03-24 21:21 ` Dmitry A. Kazakov
2009-03-25 10:07 ` patrick.gunia
2009-03-25 10:57 ` patrick.gunia
2009-03-25 11:40 ` Georg Bauhaus
2009-03-25 11:46 ` Ludovic Brenta
2009-03-25 11:55 ` patrick.gunia
2009-03-25 14:10 ` patrick.gunia
2009-03-25 14:40 ` Ludovic Brenta
2009-03-25 15:16 ` Adam Beneschan
2009-03-25 15:19 ` patrick.gunia
2009-03-25 16:52 ` Georg Bauhaus
2009-03-25 11:10 ` Dmitry A. Kazakov
2009-03-25 11:37 ` patrick.gunia
2009-03-25 12:07 ` Ludovic Brenta
2009-03-25 15:00 ` Robert A Duff
2009-03-25 11:17 ` Jean-Pierre Rosen
2009-03-26 9:04 ` Martin
2009-03-25 11:38 ` Ludovic Brenta
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox