March 13, 2018
On Tuesday, 13 March 2018 at 05:11:48 UTC, psychoticRabbit wrote:

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

No, it hasn't broken encapsulation. Encapsulation is at the module level. A class or struct and any supporting functions can be included in a single module and the private API is encapsulated from the outside world.

>
> 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 is not C++, C#, or Java. C++ uses friend to get around the issue. Java has no solution. I don't know about C#.

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

I think it's a great feature and I use it frequently. It's allows more flexibility in class design. Without it, we'd need another protection attribute to enable the concept of "private to the module".

In Java, it's recommended to manipulate private member variables through their accessors even in methods of the same class. I've always found that extreme. If you need to make a breaking change to the member variable, you already have access to all of the method internals anyway. Yes, there's room for error if you forget to make a change, but with all the support in modern IDEs and editors for find/replace, it's a simple matter to handle it all at once. And in the standard edit-compile-run cycle, any breakage is discovered right away, not weeks down the road in the field.

The same applies here. Encapsulation simply isn't broken by this feature.
March 13, 2018
On Tuesday, 13 March 2018 at 06:01:43 UTC, ketmar wrote:
>
> ah, yes, sorry: i completely forgot that C++ was invented after c# and java. mea maxima culpa!

My point was, that the 2 most widely used and popular languages on the plant, C# and Java, decided NOT to make private, something mean else, like D has done.

So the 3 most used languages got it wrong??

March 13, 2018
On Tuesday, 13 March 2018 at 06:03:11 UTC, Mike Parker wrote:
> I think it's a great feature and I use it frequently. It's allows more flexibility in class design. Without it, we'd need another protection attribute to enable the concept of "private to the module".

That's kind of my point. That's what I would have done, if for no other reason, to prevent the same syntax from having different semantics (when C++/C#/Java programmers come over to D).

And I switch between them all, and now, I have to remember D's private memeber is something very different indeed.

> In Java, it's recommended to manipulate private member variables through their accessors even in methods of the same class. I've always found that extreme.

Java is extreme in many ways ;-)

but at least, private member, is still a private member (to the class).

If my private class memeber can be directly modified outside of the class, then class encapsulation IS broken. Just saying, oh no, it's module encapsulation you should be thinking about, seems kinda strange, since we still use classes - which are their own level of encapsulation. That's the whole point of them.


March 13, 2018
psychoticRabbit wrote:

> So the 3 most used languages got it wrong??

yes.
March 13, 2018
On Tuesday, 13 March 2018 at 06:14:49 UTC, psychoticRabbit wrote:
> On Tuesday, 13 March 2018 at 06:01:43 UTC, ketmar wrote:
>>
>> ah, yes, sorry: i completely forgot that C++ was invented after c# and java. mea maxima culpa!
>
> My point was, that the 2 most widely used and popular languages on the plant, C# and Java, decided NOT to make private, something mean else, like D has done.
>
> So the 3 most used languages got it wrong??

Yes, they got it wrong! Because they don't have modules, and because Java & C# are OOP bondage-everything-is-a-class, and preach that the world spins on classes.

C++ tried to fix it with 'friend', and it shows the hack that it is.

Don't know why you think D should be just another Java or C#?
March 13, 2018
On 13/03/2018 7:14 PM, psychoticRabbit wrote:
> On Tuesday, 13 March 2018 at 06:01:43 UTC, ketmar wrote:
>>
>> ah, yes, sorry: i completely forgot that C++ was invented after c# and java. mea maxima culpa!
> 
> My point was, that the 2 most widely used and popular languages on the plant, C# and Java, decided NOT to make private, something mean else, like D has done.
> 
> So the 3 most used languages got it wrong??

Yes.

Module system comes from the ML family. As proven by the adoption by Java as of late, it is far superior to alternative designs.

March 13, 2018
On Tuesday, 13 March 2018 at 06:25:39 UTC, ketmar wrote:
> psychoticRabbit wrote:
>
>> So the 3 most used languages got it wrong??
>
> yes.

do you know any other language, where a private class memeber, is not private to the class?

(btw. that's a question, not a statement).
March 13, 2018
On Tuesday, 13 March 2018 at 06:26:13 UTC, Radu wrote:
> On Tuesday, 13 March 2018 at 06:14:49 UTC, psychoticRabbit wrote:
>> On Tuesday, 13 March 2018 at 06:01:43 UTC, ketmar wrote:
>>>
>>> ah, yes, sorry: i completely forgot that C++ was invented after c# and java. mea maxima culpa!
>>
>> My point was, that the 2 most widely used and popular languages on the plant, C# and Java, decided NOT to make private, something mean else, like D has done.
>>
>> So the 3 most used languages got it wrong??
>
> Yes, they got it wrong! Because they don't have modules, and because Java & C# are OOP bondage-everything-is-a-class, and preach that the world spins on classes.
>
> C++ tried to fix it with 'friend', and it shows the hack that it is.
>
> Don't know why you think D should be just another Java or C#?

Well I don't really. But one of the great things about D, is that a C++/C#/Java programmers can jump right in.

But when the same syntax suddenly means something really different, I tend to think that's not a good design decision.

And that's really the main point of my argument.

As I said, this was a real gotcha for me.

I only realised after I accidently tried to modify a private member directly, and discovered I did actually modify it!

Maybe, a different modifier that made it private to the module would have been a better design decision.


March 13, 2018
psychoticRabbit wrote:

> On Tuesday, 13 March 2018 at 06:25:39 UTC, ketmar wrote:
>> psychoticRabbit wrote:
>>
>>> So the 3 most used languages got it wrong??
>>
>> yes.
>
> do you know any other language, where a private class memeber, is not private to the class?
>
> (btw. that's a question, not a statement).

that is, we should stick to defective design only 'cause there is no "other D" that made it right? ;-)

also, your question is not valid. you were told several times that you're evaluating the whole thing wrong, but you're insisting on your view being right. and you're keep asking, omiting the *critical* piece of the picture: modules. you were told that in D, encapsulation unit is *module*, not class/struct. it is not a "misdesign", it is the proper modular design. it doesn't matter what others are doing in this case.

p.s.: yes, i know such language. Delphi/FreePascal.
March 13, 2018
On Tuesday, 13 March 2018 at 06:03:11 UTC, Mike Parker wrote:
>
> The same applies here. Encapsulation simply isn't broken by this feature.

What you're saying, is in D, class encapsulation is really 'module' encapsulation.

I get it. Fine. It's an intersting design decision.

But, in doing that, D has shifted the boundary of class encapsulation, to a boundary that is outside the class.

To me, that sounds like D has broken class encapsulation. I don't know how else one could describe it.

I continue to think, that class encapsulation is sacred, a well defined, well understood, concept that has been around for a very long time.

private could have still meant private, and surely someone could have come up with a different access modifier to mean 'private at module level'.

Was that too hard the language designers?

Was it not hard, but just to complex to implement?

I don't get it.