comp.lang.ada
 help / color / mirror / Atom feed
From: Maciej Sobczak <see.my.homepage@gmail.com>
Subject: Re: Default value for a record component
Date: Mon, 23 Jul 2007 12:17:46 -0700
Date: 2007-07-23T12:17:46-07:00	[thread overview]
Message-ID: <1185218266.914312.155690@n60g2000hse.googlegroups.com> (raw)
In-Reply-To: <wccir8cru49.fsf@shell01.TheWorld.com>

On 22 Lip, 23:44, Robert A Duff <bobd...@shell01.TheWorld.com> wrote:

> >> package P is
> >>    function Get_Default_Value return Integer;
> >>    type T is record
> >>       V : Integer := Get_Default_Value;
> >>    end record;
> >> end P;
>
> > No, this leaks the implementation detail (the Get_Default function) to
> > the public view and pollutes it. I don't want my users to even see it.
>
> I don't see why that's important.  You "leak" the name
> Get_Default_Value, but why is that a problem?

Why not have everything in public view then?

This function is not part of the interface. The initial value can be
part of the interface, but not the function. From the client's
perspective there is no function at all - it's existence is only an
artifact of how things are implemented, not something that the users
should be bothered with.

> You're already leaking the component V.

So? Why these should be connected?

> The fact that clients can say X.V := ...
> seems much worse

It doesn't have to be bad at all - after all, Ada allows to have full
record definitions in public view for a reason, right?

> Why do you want to hide the default value, but expose the component
> V itself?

I don't want to hide the default value - after all, the value of this
default value (hm...) is available to the user after the object is
created, so there is nothing to hide.
What I want to hide is the mechanics of where this value comes from.
Or even how often it is computed (hint: the function can be stateful).

> If you want to hide both

The point is I don't.

The C++ version:

class T
{
public:
   T() : V(getDefault()) {}

   int V;

private:
   static int getDefault();
};

(or even I can hide getDefault in the implementation file completely,
without even mentioning it in the class definition)

> > Ada needs real constructors, not just initial values.
>
> I don't get it.  Please explain.

The visibility of a component and the mechanics of computing its
initial value are orthogonal and should not depend on one another. I
can have completely separate reasons to expose or hide either of them.

--
Maciej Sobczak
http://www.msobczak.com/




  reply	other threads:[~2007-07-23 19:17 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-21 21:19 Default value for a record component Maciej Sobczak
2007-07-22  8:08 ` Dmitry A. Kazakov
2007-07-22 19:44   ` Maciej Sobczak
2007-07-22 21:44     ` Robert A Duff
2007-07-23 19:17       ` Maciej Sobczak [this message]
2007-07-23 19:41         ` Dmitry A. Kazakov
2007-07-22 20:01   ` Jeffrey R. Carter
2007-07-24  1:27 ` Randy Brukardt
2007-07-24  9:54   ` Maciej Sobczak
2007-07-24 19:12     ` 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