Jump to page: 1 28  
Page
Thread overview
how to make private class member private
Mar 13, 2018
psychoticRabbit
Mar 13, 2018
rikki cattermole
Mar 13, 2018
Jonathan M Davis
Mar 13, 2018
psychoticRabbit
Mar 13, 2018
Mike Parker
Mar 13, 2018
psychoticRabbit
Mar 13, 2018
ketmar
Mar 13, 2018
psychoticRabbit
Mar 13, 2018
ketmar
Mar 13, 2018
psychoticRabbit
Mar 13, 2018
ketmar
Mar 13, 2018
psychoticRabbit
Mar 13, 2018
ketmar
Mar 13, 2018
psychoticRabbit
Mar 13, 2018
ketmar
Mar 13, 2018
Radu
Mar 13, 2018
psychoticRabbit
Mar 13, 2018
rikki cattermole
Mar 13, 2018
Mike Parker
Mar 13, 2018
psychoticRabbit
Mar 13, 2018
psychoticRabbit
Mar 13, 2018
rikki cattermole
Mar 13, 2018
psychoticRabbit
Mar 13, 2018
Alex
Mar 13, 2018
psychoticRabbit
Mar 13, 2018
rikki cattermole
Mar 13, 2018
psychoticRabbit
Mar 13, 2018
rikki cattermole
Mar 13, 2018
psychoticRabbit
Mar 13, 2018
aliak
Mar 13, 2018
Mike Parker
Mar 13, 2018
psychoticRabbit
Mar 13, 2018
Mike Parker
Mar 13, 2018
psychoticRabbit
Mar 13, 2018
Nathan S.
Mar 13, 2018
psychoticRabbit
Mar 13, 2018
psychoticRabbit
Mar 13, 2018
Adam D. Ruppe
Mar 13, 2018
psychoticRabbit
Mar 13, 2018
Radu
Mar 13, 2018
psychoticRabbit
Mar 18, 2018
Tony
Mar 18, 2018
Jonathan M Davis
Mar 18, 2018
Tony
Mar 18, 2018
Jonathan M Davis
Mar 18, 2018
Tony
Mar 17, 2018
Nick Treleaven
Mar 17, 2018
psychoticRabbit
Mar 17, 2018
bauss
Mar 17, 2018
psychoticRabbit
Mar 17, 2018
bauss
Mar 17, 2018
arturg
Mar 17, 2018
Adam D. Ruppe
Mar 17, 2018
psychoticRabbit
Mar 18, 2018
bauss
Mar 18, 2018
psychoticRabbit
Mar 18, 2018
Alex
Mar 19, 2018
psychoticRabbit
Mar 19, 2018
bauss
Mar 18, 2018
Alain Soap
Mar 18, 2018
psychoticRabbit
Mar 18, 2018
Alain Soap
Mar 13, 2018
ketmar
Mar 13, 2018
Jonathan M Davis
Mar 13, 2018
Nathan S.
Mar 13, 2018
Jonathan M Davis
Mar 15, 2018
Nathan S.
Mar 13, 2018
Jonathan M Davis
Mar 17, 2018
Nick Treleaven
Mar 19, 2018
psychoticRabbit
Mar 29, 2018
Nick Treleaven
Mar 13, 2018
JN
March 13, 2018
I cannot get my head around, why private is not private, in D.

How do I make a private member, private?

-----
module test;

import std.stdio;

void main()
{
    myClass c = new myClass();
    c.myPrivateClassMember= "wtf";
    writeln(c.myPrivateClassMember);
}

class myClass
{
    private string myPrivateClassMember; // private does not mean private anymore??
}

------
March 13, 2018
Visibility modifiers in D are for the module, not class or struct.

This is very useful to be able to access internal stuff outside of the abstraction and modify it sanely. While also keeping others at bay.
March 12, 2018
On Tuesday, March 13, 2018 01:12:15 psychoticRabbit via Digitalmars-d-learn wrote:
> I cannot get my head around, why private is not private, in D.
>
> How do I make a private member, private?
>
> -----
> module test;
>
> import std.stdio;
>
> void main()
> {
>      myClass c = new myClass();
>      c.myPrivateClassMember= "wtf";
>      writeln(c.myPrivateClassMember);
> }
>
> class myClass
> {
>      private string myPrivateClassMember; // private does not mean
> private anymore??
> }
>
> ------

private is private to the module, not the class. There is no way in D to restrict the rest of the module from accessing the members of a class. This simplification makes it so that stuff like C++'s friend are unnecessary. If your class in a separate module from main, then main won't be able to access its private members.

- Jonathan M Davis

March 13, 2018
On Tuesday, 13 March 2018 at 01:39:13 UTC, Jonathan M Davis wrote:
>
> private is private to the module, not the class. There is no way in D to restrict the rest of the module from accessing the members of a class. This simplification makes it so that stuff like C++'s friend are unnecessary. If your class in a separate module from main, then main won't be able to access its private members.
>
> - Jonathan M Davis

Mmm.. I don't think I like it.

I feel you should be able to make a member of a class, private, regardless of where the class is located. This seems to break the concept of class encapsulation.

No. I don't like it at all.

March 13, 2018
On Tuesday, 13 March 2018 at 02:06:57 UTC, psychoticRabbit wrote:
>
> Mmm.. I don't think I like it.
>
> I feel you should be able to make a member of a class, private, regardless of where the class is located. This seems to break the concept of class encapsulation.
>
> No. I don't like it at all.

If you have access to the module source, you have access to the source of types inside it. Making the module the lowest level of encapsulation makes sense from that perspective.
March 13, 2018
psychoticRabbit wrote:

> On Tuesday, 13 March 2018 at 01:39:13 UTC, Jonathan M Davis wrote:
>>
>> private is private to the module, not the class. There is no way in D to restrict the rest of the module from accessing the members of a class. This simplification makes it so that stuff like C++'s friend are unnecessary. If your class in a separate module from main, then main won't be able to access its private members.
>>
>> - Jonathan M Davis
>
> Mmm.. I don't think I like it.
>
> I feel you should be able to make a member of a class, private, regardless of where the class is located. This seems to break the concept of class encapsulation.
>
> No. I don't like it at all.

just stop thinking in C/C++ "#include" terms. there, you have no other ways to restrict data access, so they were forced to make it broken, and then introduce "friends" just to workaround the fact that there are no modules in C++.

instead, start thinking with modules in mind. module is THE unit of incapsulation. there is nothing wrong in isolating class or two in a module. then, to make imports manageable, either create a package of that, or just a dummy module that does `public import xxx;` for everything.
March 13, 2018
On Tuesday, 13 March 2018 at 02:24:38 UTC, Mike Parker wrote:
> On Tuesday, 13 March 2018 at 02:06:57 UTC, psychoticRabbit wrote:
>>
>> Mmm.. I don't think I like it.
>>
>> I feel you should be able to make a member of a class, private, regardless of where the class is located. This seems to break the concept of class encapsulation.
>>
>> No. I don't like it at all.
>
> If you have access to the module source, you have access to the source of types inside it. Making the module the lowest level of encapsulation makes sense from that perspective.

There are two problems I see:

1st - D has broken the concept of class encapsulation, simply for convenience at the module level. Not good in my opinion.

2nd - C++/C#/Java programmers will come to D, use the same syntax, but get very different semantics. Not good in my opinion. (i.e. I only realised private was not private, by accident).

D has made many good design decisions. I do not see this as one of them.

March 13, 2018
psychoticRabbit wrote:

> There are two problems I see:
1) it is not how C++ done it.
2) it is not how C++ done it.

and you're completely right: it is not how C++ done it.
March 13, 2018
On Tuesday, 13 March 2018 at 05:52:55 UTC, ketmar wrote:
> psychoticRabbit wrote:
>
>> There are two problems I see:
> 1) it is not how C++ done it.
> 2) it is not how C++ done it.
>
> and you're completely right: it is not how C++ done it.

umm...didn't you forget something:

1) it is not how C# done it.
2) it is not how C# done it.

1) it is not how Java done it.
2) it is not how Java done it.

March 13, 2018
psychoticRabbit wrote:

> On Tuesday, 13 March 2018 at 05:52:55 UTC, ketmar wrote:
>> psychoticRabbit wrote:
>>
>>> There are two problems I see:
>> 1) it is not how C++ done it.
>> 2) it is not how C++ done it.
>>
>> and you're completely right: it is not how C++ done it.
>
> umm...didn't you forget something:
>
> 1) it is not how C# done it.
> 2) it is not how C# done it.
>
> 1) it is not how Java done it.
> 2) it is not how Java done it.

ah, yes, sorry: i completely forgot that C++ was invented after c# and java. mea maxima culpa!
« First   ‹ Prev
1 2 3 4 5 6 7 8