June 13, 2022

On Monday, 13 June 2022 at 09:12:47 UTC, user1234 wrote:

>

On Monday, 13 June 2022 at 09:09:08 UTC, user1234 wrote:

>

On Monday, 13 June 2022 at 08:13:14 UTC, claptrap wrote:

>

[...]

True but ObjFPC has strict private too since a while: demo.
This does exactly what is discussed on the D forum since a week.

well the online compilers are too old, but if you try this code with a more recent compiler

{$MODE OBJFPC}{$H+}
{$MODESWITCH ADVANCEDRECORDS}
type TS = record
  private
    a: integer;
  strict private
    b: integer;
end;

var
 s: TS;

begin
  s.a := 1; // OK
  s.b := 1; // NG
end.

this gives

>

project1.lpr(15,5) Error: identifier idents no member "b"

You should have used compiler explorer. :)

https://godbolt.org/z/6M7be7M57

June 13, 2022

On Monday, 13 June 2022 at 10:44:43 UTC, bauss wrote:

>

On Monday, 13 June 2022 at 10:43:09 UTC, bauss wrote:

>

On Monday, 13 June 2022 at 10:13:30 UTC, Mike Parker wrote:

>

Look, I'm not against the logic, I completely understand it from the perspective of that a subclass shouldn't have access to private members of the class it inherits from, BUT remember in D private doesn't mean private to the class, so the symbol should only be private when accessed from anywhere but the module.

To add on to this; it's not a matter of what's more logical, but simply that D is contradicting itself, so either D stops being referred to as "module private" or this will be deemed an unfinished feature/bug.

And I'm arguing that this is exactly what we should expect from private-to-the-module, since B is not declared in the same module as the superclass, so it's neither unfinished nor a bug.

June 13, 2022

On Monday, 13 June 2022 at 10:49:37 UTC, Paulo Pinto wrote:

>

On Monday, 13 June 2022 at 09:12:47 UTC, user1234 wrote:

>

On Monday, 13 June 2022 at 09:09:08 UTC, user1234 wrote:

>

[...]

well the online compilers are too old, but if you try this code with a more recent compiler

{$MODE OBJFPC}{$H+}
{$MODESWITCH ADVANCEDRECORDS}
type TS = record
  private
    a: integer;
  strict private
    b: integer;
end;

var
 s: TS;

begin
  s.a := 1; // OK
  s.b := 1; // NG
end.

this gives

>

[...]

You should have used compiler explorer. :)

https://godbolt.org/z/6M7be7M57

nice, even highlighting of "strict private" is correct there.
one more kudo for compiler explorer.

June 13, 2022

On Monday, 13 June 2022 at 10:51:10 UTC, Mike Parker wrote:

>

And I'm arguing that this is exactly what we should expect from private-to-the-module, since B is not declared in the same module as the superclass, so it's neither unfinished nor a bug.

It breaks the sub-typing requirement.

If you get more access by recasting a pointer to the super-type then the sub-typing relation cannot be satisfied.

Hence, it is certainly broken. If it is not a bug, then it is broken by design. Which is no better.

June 13, 2022

On Monday, 13 June 2022 at 10:55:36 UTC, Ola Fosheim Grøstad wrote:

>

On Monday, 13 June 2022 at 10:51:10 UTC, Mike Parker wrote:

>

And I'm arguing that this is exactly what we should expect from private-to-the-module, since B is not declared in the same module as the superclass, so it's neither unfinished nor a bug.

It breaks the sub-typing requirement.

If you get more access by recasting a pointer to the super-type then the sub-typing relation cannot be satisfied.

Hence, it is certainly broken. If it is not a bug, then it is broken by design. Which is no better.

Or to explain it in simple terms:

A cast to a supertype should only imply additional restrictions.

In this case the opposite happens. So this aspect of the type system is broken.

June 13, 2022

On Monday, 13 June 2022 at 11:00:17 UTC, Ola Fosheim Grøstad wrote:

>

Or to explain it in simple terms:

A cast to a supertype should only imply additional restrictions.

In this case the opposite happens. So this aspect of the type system is broken.

Or perhaps this formulation is less confusing:

A cast to a superclass is an act of forgetfulness

Being forgetful should not enable you do do more. The less you know, the less you should be able to do. The more you know, the more you should be able to do.

June 13, 2022

On Monday, 13 June 2022 at 10:51:10 UTC, Mike Parker wrote:

>

On Monday, 13 June 2022 at 10:44:43 UTC, bauss wrote:

>

On Monday, 13 June 2022 at 10:43:09 UTC, bauss wrote:

>

On Monday, 13 June 2022 at 10:13:30 UTC, Mike Parker wrote:

>

Look, I'm not against the logic, I completely understand it from the perspective of that a subclass shouldn't have access to private members of the class it inherits from, BUT remember in D private doesn't mean private to the class, so the symbol should only be private when accessed from anywhere but the module.

To add on to this; it's not a matter of what's more logical, but simply that D is contradicting itself, so either D stops being referred to as "module private" or this will be deemed an unfinished feature/bug.

And I'm arguing that this is exactly what we should expect from private-to-the-module, since B is not declared in the same module as the superclass, so it's neither unfinished nor a bug.

Now THIS is why D is unpopular. It is a unfinished or a bug, while the people maintaining it say it isn't.

Take the source code from the original post: https://forum.dlang.org/post/yyurtzlglypsvgizxodg@forum.dlang.org

import b;
void handle(Bar child)
{
    child.Foo._c += child.c; // works
    child._c     += child.c; // error no property _c
}

Both work, you can access _c through child and it is a also private and can't be accessed through child. So which is it? Is this what you define as "working" as intended?

June 13, 2022

It's the name of the language ;-)

Try to find "D". You will get a long list of results from everything and everyone.
Renaming to something like would DFutureC help.

Regards, Ozan

June 13, 2022

On Monday, 13 June 2022 at 10:55:36 UTC, Ola Fosheim Grøstad wrote:

>

On Monday, 13 June 2022 at 10:51:10 UTC, Mike Parker wrote:

>

And I'm arguing that this is exactly what we should expect from private-to-the-module, since B is not declared in the same module as the superclass, so it's neither unfinished nor a bug.

It breaks the sub-typing requirement.

If you get more access by recasting a pointer to the super-type then the sub-typing relation cannot be satisfied.

And the reason is the private member of the class shouldn't be accessible outside its declaration scope in the first place. Module-level 'private' is dysfunctional by design.

>

Hence, it is certainly broken. If it is not a bug, then it is broken by design. Which is no better.

June 13, 2022

On Monday, 13 June 2022 at 12:03:10 UTC, Max Samukha wrote:

>

Module-level 'private' is dysfunctional by design.

No! We don't need encapsulation!
We are all friends.
Your variable, I will use it if I want to!You should happy however I use it,we are friends!