comp.lang.ada
 help / color / mirror / Atom feed
* What is the difference of "with null record" and "with private"?
@ 2014-05-23 18:19 Victor Porton
  2014-05-23 18:21 ` Victor Porton
                   ` (3 more replies)
  0 siblings, 4 replies; 12+ messages in thread
From: Victor Porton @ 2014-05-23 18:19 UTC (permalink / raw)


What is the difference of "with null record" and "with private"?

Both denote a descendant of a type with no new additional public fields.

I see no difference. What is the difference and when one or another should 
be used?

-- 
Victor Porton - http://portonvictor.org

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

* Re: What is the difference of "with null record" and "with private"?
  2014-05-23 18:19 What is the difference of "with null record" and "with private"? Victor Porton
@ 2014-05-23 18:21 ` Victor Porton
  2014-05-23 18:55   ` mockturtle
  2014-05-23 18:59 ` Dan'l Miller
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 12+ messages in thread
From: Victor Porton @ 2014-05-23 18:21 UTC (permalink / raw)


Victor Porton wrote:

> What is the difference of "with null record" and "with private"?
> 
> Both denote a descendant of a type with no new additional public fields.
> 
> I see no difference. What is the difference and when one or another should
> be used?

Clarification of my question: I mean the case when the full view of the type 
is "with null record".

-- 
Victor Porton - http://portonvictor.org


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

* Re: What is the difference of "with null record" and "with private"?
  2014-05-23 18:21 ` Victor Porton
@ 2014-05-23 18:55   ` mockturtle
  2014-05-23 19:42     ` Adam Beneschan
  2014-05-23 20:45     ` Georg Bauhaus
  0 siblings, 2 replies; 12+ messages in thread
From: mockturtle @ 2014-05-23 18:55 UTC (permalink / raw)


On Friday, May 23, 2014 8:21:21 PM UTC+2, Victor Porton wrote:
> Victor Porton wrote:
> 
> 
> 
> > What is the difference of "with null record" and "with private"?
> > 
> > Both denote a descendant of a type with no new additional public fields.
> > I see no difference. What is the difference and when one or another should
> > be used?
> 
> Clarification of my question: I mean the case when the full view of the type 
> is "with null record".
> 

Well, as I see it, it is more a matter of visibility.  It is true that in both cases you have the same "structure" (namely, the ancestor with no new fields), but in the case of "with private" the "users" (that is, the packages that use the derived type) do not know that...

One could say that "with private" is used to hide the internal details of your type and that if the extension is done with a "null record" there is not much to hide. Actually, I cannot imagine a case where the fact that it is public that the extension is null can cause loss of maintainability the day some new fields are added.  Nevertheless, usually I prefer the "with private" form for uniformity.

Riccardo

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

* Re: What is the difference of "with null record" and "with private"?
  2014-05-23 18:19 What is the difference of "with null record" and "with private"? Victor Porton
  2014-05-23 18:21 ` Victor Porton
@ 2014-05-23 18:59 ` Dan'l Miller
  2014-05-23 21:45 ` Shark8
  2014-05-23 21:55 ` Randy Brukardt
  3 siblings, 0 replies; 12+ messages in thread
From: Dan'l Miller @ 2014-05-23 18:59 UTC (permalink / raw)


On Friday, May 23, 2014 1:19:16 PM UTC-5, Victor Porton wrote:
> What is the difference of "with null record" and "with private"?
> 
> 
> 
> Both denote a descendant of a type with no new additional public fields.

You will see the answer when you focus on why you yourself wrote the word "public" there.  I suspect that even you would suspect the falsehood of:  Both denote a descendant of a type with no additional fields.

> What is the difference and when one or another should be used?

  When the public view of a record is declared 'with null record', then that record has no additional fields--neither public nor private/encapsulated.  When the public view of the record is declared "with private" the record may optionally have additional private/encapsulated fields that are maintained safely by subprograms in that package.

> I see no difference.

That is because you are wearing the blinders of "public".  Look from the bigger picture of the 'private' vantage point to see what more can go on behind the curtain.

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

* Re: What is the difference of "with null record" and "with private"?
  2014-05-23 18:55   ` mockturtle
@ 2014-05-23 19:42     ` Adam Beneschan
  2014-05-23 22:05       ` Adam Beneschan
  2014-05-24  8:19       ` mockturtle
  2014-05-23 20:45     ` Georg Bauhaus
  1 sibling, 2 replies; 12+ messages in thread
From: Adam Beneschan @ 2014-05-23 19:42 UTC (permalink / raw)


On Friday, May 23, 2014 11:55:09 AM UTC-7, mockturtle wrote:
> On Friday, May 23, 2014 8:21:21 PM UTC+2, Victor Porton wrote:

> One could say that "with private" is used to hide the internal details of your type and that if the extension is done with a "null record" there is not much to hide. Actually, I cannot imagine a case where the fact that it is public that the extension is null can cause loss of maintainability the day some new fields are added.  Nevertheless, usually I prefer the "with private" form for uniformity.

I can easily imagine a case.

    package Pack0 is
        type Base_Record is tagged record
            F1 : Integer;
        end record;
    end Pack0;

    package Pack1 is
        type An_Extension is new Base_Record with null record;
        type A_Private_Extension is new Base_Record with private;
    private
        type A_Private_Extension is new Base_Record with null record;
    end Pack1;

...

    procedure Proc is        -- in some other package
        A1 : An_Extension := (F1 => 3);         -- legal 
        A2 : A_Private_Extension := (F1 => 3);  -- illegal
    begin 
        ...

The point here is that when declaring an aggregate of type An_Extension, the program can count on the fact that the extension has no additional fields, while for A_Private_Extension, it can't.  **The fact that A_Private_Extension has no additional fields is an implementation detail that is hidden from the rest of the program.**  It's not true that there is "nothing to hide" ... the fact that there are no details is definitely something that may need to be hidden.  Suppose that you later change the implementation of Pack1 and decide to add some fields to A_Private_Extension.  Since the implementation details are hidden, you can change them without worrying that you will break something else in some other package far, far away.  (This wouldn't be true if the declaration of A2 were legal.)  And that's the whole purpose of "private" and the whole purpose of encapsulation in general--so that hidden implementation details can be changed without worrying about having to search every user of the package to see if it needs to change.

                               -- Adam


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

* Re: What is the difference of "with null record" and "with private"?
  2014-05-23 18:55   ` mockturtle
  2014-05-23 19:42     ` Adam Beneschan
@ 2014-05-23 20:45     ` Georg Bauhaus
  1 sibling, 0 replies; 12+ messages in thread
From: Georg Bauhaus @ 2014-05-23 20:45 UTC (permalink / raw)


On 23/05/14 20:55, mockturtle wrote:
> Well, as I see it, it is more a matter of visibility.

"with private" acts pleasantly strong WRT visibility,
in a technical sense, even "locally". Leaving out nested
packages, still some of the types below must be rejected
by the compiler:

package Privacy is

    type T0 is tagged private;
    type T  is tagged null record;

    type T1  is new T0 with private;
    type T1n is new T0 with null record;

    type Np  is new T  with private;
    type N   is new T  with null record;
    type Np0 is new T0 with private;
    type N0  is new T0 with null record;

private
    type T0  is tagged null record;

    type T1  is new T0 with null record;
    type Np  is new T  with null record;
    type Np0 is new T0 with null record;
end Privacy;

All of these have to do with when a type's definition
is finished, and the combination of placement and
privacy control will affect later derivations, too.



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

* Re: What is the difference of "with null record" and "with private"?
  2014-05-23 18:19 What is the difference of "with null record" and "with private"? Victor Porton
  2014-05-23 18:21 ` Victor Porton
  2014-05-23 18:59 ` Dan'l Miller
@ 2014-05-23 21:45 ` Shark8
  2014-05-24 10:49   ` Victor Porton
  2014-05-23 21:55 ` Randy Brukardt
  3 siblings, 1 reply; 12+ messages in thread
From: Shark8 @ 2014-05-23 21:45 UTC (permalink / raw)


On 23-May-14 12:19, Victor Porton wrote:
> What is the difference of "with null record" and "with private"?
>
> Both denote a descendant of a type with no new additional public fields.

Incorrect.
Null record does what you indicate, with private means that any fields 
aren't visible/public. Example:

Package Example is
     Type Parent is tagged record
         Data_1 : Integer;
     end record;

     -- Returns Data_1
     Function Get_Data (Item : Parent) return Integer;

     -- Contains Data_2, but this field is private.
     Type Child is new Parent with private;

     -- Returns Data_2
     Function Get_Data (Item : Child) return Integer;


private
     Type Child is new Parent with record
         Data_2 : Integer;
     end record;

     Function Get_Data (Item : Parent) return Integer is (Item.Data_1);
     Function Get_Data (Item : Child)  return Integer is (Item.Data_2);

End Example;

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

* Re: What is the difference of "with null record" and "with private"?
  2014-05-23 18:19 What is the difference of "with null record" and "with private"? Victor Porton
                   ` (2 preceding siblings ...)
  2014-05-23 21:45 ` Shark8
@ 2014-05-23 21:55 ` Randy Brukardt
  3 siblings, 0 replies; 12+ messages in thread
From: Randy Brukardt @ 2014-05-23 21:55 UTC (permalink / raw)


"Victor Porton" <porton@narod.ru> wrote in message 
news:llo3f0$mqp$1@speranza.aioe.org...
> What is the difference of "with null record" and "with private"?
>
> Both denote a descendant of a type with no new additional public fields.
>
> I see no difference. What is the difference and when one or another should
> be used?

There's at least one difference: "null record" automatically creates 
inherited functions returning the type for you, while "private" (and any 
components) means you have to do this manually.

I personally consider this a mis-feature of Ada and would hope no one 
depends too much on it (it should be available for all types or none, IMHO). 
But it can make for some maintenance headaches down the road for "null 
record".

                                                        Randy.


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

* Re: What is the difference of "with null record" and "with private"?
  2014-05-23 19:42     ` Adam Beneschan
@ 2014-05-23 22:05       ` Adam Beneschan
  2014-05-24  8:19       ` mockturtle
  1 sibling, 0 replies; 12+ messages in thread
From: Adam Beneschan @ 2014-05-23 22:05 UTC (permalink / raw)


On Friday, May 23, 2014 12:42:06 PM UTC-7, Adam Beneschan wrote:


> It's not true that there is "nothing to hide" ... the fact that there are no details is definitely something that may need to be hidden.  

That should have been "the fact that there are no extension fields ..."

                                    -- Adam

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

* Re: What is the difference of "with null record" and "with private"?
  2014-05-23 19:42     ` Adam Beneschan
  2014-05-23 22:05       ` Adam Beneschan
@ 2014-05-24  8:19       ` mockturtle
  1 sibling, 0 replies; 12+ messages in thread
From: mockturtle @ 2014-05-24  8:19 UTC (permalink / raw)


On Friday, May 23, 2014 9:42:06 PM UTC+2, Adam Beneschan wrote:
> On Friday, May 23, 2014 11:55:09 AM UTC-7, mockturtle wrote:
> 
> > On Friday, May 23, 2014 8:21:21 PM UTC+2, Victor Porton wrote:
> 
> 
> 
> > One could say that "with private" is used to hide the internal details of your type and that if the extension is done with a "null record" there is not much to hide. Actually, I cannot imagine a case where the fact that it is public that the extension is null can cause loss of maintainability the day some new fields are added.  Nevertheless, usually I prefer the "with private" form for uniformity.
> 
> 
> 
> I can easily imagine a case.
(snip)
> The point here is that when declaring an aggregate of type An_Extension, the program can count on the fact that the extension has no additional fields, while for A_Private_Extension, it can't.  **The fact that A_Private_Extension has no additional fields is an implementation detail that is hidden from the rest of the program.**  It's not true that there is "nothing to hide" ... the fact that there are no details is definitely something that may need to be hidden.  Suppose that you later change the implementation of Pack1 and decide to add some fields to A_Private_Extension.  Since the implementation details are hidden, you can change them without worrying that you will break something else in some other package far, far away.  (This wouldn't be true if the declaration of A2 were legal.)  And that's the whole purpose of "private" and the whole purpose of encapsulation in general--so that hidden implementation details can be changed without worrying about having to search every user of the package to see if it needs to change.
> 

Touche'.  You are right.

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

* Re: What is the difference of "with null record" and "with private"?
  2014-05-23 21:45 ` Shark8
@ 2014-05-24 10:49   ` Victor Porton
  2014-05-24 17:33     ` Shark8
  0 siblings, 1 reply; 12+ messages in thread
From: Victor Porton @ 2014-05-24 10:49 UTC (permalink / raw)


Shark8 wrote:

> On 23-May-14 12:19, Victor Porton wrote:
>> What is the difference of "with null record" and "with private"?
>>
>> Both denote a descendant of a type with no new additional public fields.
> 
> Incorrect.
> Null record does what you indicate, with private means that any fields
> aren't visible/public. Example:

I've said "no new additional PUBLIC fields" not just "no new additional 
fields"!

> Package Example is
>      Type Parent is tagged record
>          Data_1 : Integer;
>      end record;
> 
>      -- Returns Data_1
>      Function Get_Data (Item : Parent) return Integer;
> 
>      -- Contains Data_2, but this field is private.
>      Type Child is new Parent with private;
> 
>      -- Returns Data_2
>      Function Get_Data (Item : Child) return Integer;
> 
> 
> private
>      Type Child is new Parent with record
>          Data_2 : Integer;
>      end record;
> 
>      Function Get_Data (Item : Parent) return Integer is (Item.Data_1);
>      Function Get_Data (Item : Child)  return Integer is (Item.Data_2);
> 
> End Example;

-- 
Victor Porton - http://portonvictor.org


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

* Re: What is the difference of "with null record" and "with private"?
  2014-05-24 10:49   ` Victor Porton
@ 2014-05-24 17:33     ` Shark8
  0 siblings, 0 replies; 12+ messages in thread
From: Shark8 @ 2014-05-24 17:33 UTC (permalink / raw)


On 24-May-14 04:49, Victor Porton wrote:
> Shark8 wrote:
>
>> On 23-May-14 12:19, Victor Porton wrote:
>>> What is the difference of "with null record" and "with private"?
>>>
>>> Both denote a descendant of a type with no new additional public fields.
>>
>> Incorrect.
>> Null record does what you indicate, with private means that any fields
>> aren't visible/public. Example:
>
> I've said "no new additional PUBLIC fields" not just "no new additional
> fields"!

So? The point stands the method given does something quite different -- 
this means that you can alter behavior w/o changing the underlying 
structure -- say renaming 'append' and 'prepend' inversely on a vector 
so that your operations work from the other end w/o any modification to 
the client code.

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

end of thread, other threads:[~2014-05-24 17:33 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-23 18:19 What is the difference of "with null record" and "with private"? Victor Porton
2014-05-23 18:21 ` Victor Porton
2014-05-23 18:55   ` mockturtle
2014-05-23 19:42     ` Adam Beneschan
2014-05-23 22:05       ` Adam Beneschan
2014-05-24  8:19       ` mockturtle
2014-05-23 20:45     ` Georg Bauhaus
2014-05-23 18:59 ` Dan'l Miller
2014-05-23 21:45 ` Shark8
2014-05-24 10:49   ` Victor Porton
2014-05-24 17:33     ` Shark8
2014-05-23 21:55 ` Randy Brukardt

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