comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: Default value for a record component
Date: Sun, 22 Jul 2007 17:44:38 -0400
Date: 2007-07-22T17:44:38-04:00	[thread overview]
Message-ID: <wccir8cru49.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: 1185133442.532463.301960@r34g2000hsd.googlegroups.com

Maciej Sobczak <see.my.homepage@gmail.com> writes:

> On 22 Lip, 10:08, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
>
>> > I would like extend it and do this:
>>
>> > package P is
>> >    type T is record
>> >       V : Integer := Get_Default_Value;
>> >    end record;
>> > private
>> >    function Get_Default_Value return Integer;
>> > end P;
>>
>> > without losing any of the properties of the original solution and
>> > without "leaking" any implementation detail to the public view.
>
>> Yes:
>>
>> 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?

You're already leaking the component V.
The fact that clients can say X.V := ...
seems much worse than the fact that they can say
Mumble : Integer := Get_Default_Value.

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

If you want to hide both, then make the type private, and then you can
hide Get_Default_Value also.  Usually a good idea.

> Ada needs real constructors, not just initial values.

I don't get it.  Please explain.

- Bob



  reply	other threads:[~2007-07-22 21:44 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 [this message]
2007-07-23 19:17       ` Maciej Sobczak
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