Extending D's support for object-oriented design with private(this)

NotYouAgain NotYouAgain at gmail.com
Mon Apr 29 23:21:46 UTC 2024


On Monday, 29 April 2024 at 13:39:17 UTC, Basile B. wrote:
>
> The D solution is to encourage splitting modules. ...

You could it that way, I guess.

I prefer to say, that D puts the burden of correctness, fully on 
the programmer.

The Swift community already went through this issue over 8 years 
ago, and the decided a fix was warranted (and I mean the very, 
very experienced people who design Swift).

You can see some of those discussion here (and note how 
professional those discussions are too) - 
https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160321/013261.html

That any oo programmer that comes to D should have to explain to 
anyone in the D community the value of an option to declare a 
private class member and have to argue it for years...no 
decades.. is just pathetic. I cannot describe it any other way.

Yes, I know people in D disagree. Fine. That doesn't make them 
right. Does it make me right...well..one can just look at what 
Swift have done (fixed), Javascript have done (fixed), C++, C#, 
Java, Haskell....have by design ... and I can go on and on....

As I said before, the proof of a type is in the type of its 
proof. Not just each class, but each unittest has to go in its 
own module. It's a totally uncessary burden to place on 
programmers in order to the design contraint they want on their 
class type, and appropriate enforcement of that design by the 
compiler. If people disagree, fine. I don't accept that they are 
a correct, and the proof is in all the languages I just 
mentioned. I think those languages represent the vast majority of 
programmers in the world. D represents less than atom of that 
amount.

But just remember to annotate your class types with the 
annotation below, and I'm sure everything will work out just fine 
for you..and your users, and those who have to maintain your code.

------
module test;

@BEWARE_all_code_in_this_class_is_a_c++_like_friend_of_this_class_including_unittests.
class Firefighter
{
     private void DoSomethingATraineeShouldNotDo() {}

}

class TraineeFirefighter : Firefighter {}

unittest
{
     TraineeFirefighter joe = new TraineeFirefighter();
     joe.DoSomethingATraineeShouldNotDo();

}
----------


More information about the dip.ideas mailing list