Sealed classes - would you want them in D?
KingJoffrey
KingJoffrey at KingJoffrey.com
Sun May 13 01:52:20 UTC 2018
On Saturday, 12 May 2018 at 18:36:59 UTC, Walter Bright wrote:
> On 5/12/2018 9:42 AM, Mike Parker wrote:
>> Thank goodness we don't have to do this silliness.
>
> I always thought the 'friend' business in C++ was an awful
> hack. But C++ didn't have modules, and modules are a much
> better solution to that problem.
Modules would only be a better solution, if, and only if, the
programmer still had control over class level encapsulation.
At least 'friend' in c++, is in the control of the programmer.
D has decided the programmer doesn't need this control anymore,
takes that control away, and gives it to the module - the
programmer has no say in it - even if the programmer want's it
private, the module overrides private!!
I would expect, that like me, 10's of millions of other
programmers would not be comfortable with this.
That the '< 1000' D programmers think otherwise, doesn't make the
case.
Go back and give the programmer control, as to whether the class
or the module has the greater authority, and perhaps...then... D
will attract more programmers.
Feel free to show the code below, to all the C#/C++/Java
programmers out there - I'm sure they'll love what D has done
with the class-module interaction.
================================
module test;
import std.stdio : writeln;
void main()
{
Person p = new Person("King Joffrey");
writeln(p.getName); // I designed my class to present this
interface.
writeln(p._name); // The module couldn't care less about your
interface.
p._name = "King Walter"; // even worse, the module can
de-throne the king!!
writeln(p._name);
}
class Person
{
private string _name;
public void setName(string name)
{
this._name = name;
}
public string getName()
{
return ProperName(this._name);
}
public this(string name)
{
_name = name;
}
private static string ProperName(string name)
{
return name ~ " : The one true king!";
}
}
===========================================
More information about the Digitalmars-d
mailing list