November 09
On Thursday, 8 November 2018 at 23:50:18 UTC, TheFireFighter wrote:
> No it is not. You can keep saying there is, but it doesn't make it so.
> ...
> We don't seem to be on the same page here...do you misunderstand what I want?

Fair enough, the exact thing you want is not possible. I understand that. It's also a fact that you can't have a value-type class. But just because you can't have a value type *class* doesn't mean you can't have a value-type aggregate: there is struct. The higher goal of encapsulating classes is possible by writing one per module and using package.d, it's just not possible with the restriction that multiple classes must be in the same file.

> Regarding the 'burden' to the D langauge, by providing the programmer with a tool to specify better encapsulation of code *within* the module:
>
> [quote]
>
> i.e. better encapsulation really is a good thing (although for many, it a lesson that needs to be learned).

Walter considers the module the lowest level of encapsulation, while you consider the class to be that. Neither is proven to be better so far. To change the D language in that regard, you have to convince people that class-private is superior/important enough to warrant the language change. Unfortunately, the arguments given so far have not done that yet, since they mostly appeal to feeling, fear and 'the obvious' as mentioned earlier.
November 09
On Thursday, 8 November 2018 at 23:50:18 UTC, TheFireFighter wrote:
> i.e. better encapsulation really is a good thing (although for  many, it a lesson that needs to be learned).

Public/private/protected are hacks anyway - and many object-oriented languages don't have it. They only provide extremely limited encapsulation ; the client still sees the non-public part, and can depend on it in unexpected ways:

// my_module.d
struct MyStruct
{
private:
  char[1024] data;
}

class MyClass
{
protected:
  abstract void f();
};

// main.d
import my_module;
import std.traits;
import std.stdio;

int main()
{
  // depends on the list of private
  writefln("MyStruct.sizeof: %s", MyStruct.sizeof); members

  // depends on wether 'f' is declared abstract or not.
  writefln("isAbstractClass!MyClass: %s", isAbstractClass!MyClass);

  return 0;
}

If you want perfect encapsulation, use interfaces (as already said in this thread), or PIMPL.

Next ›   Last »
1 2 3 4 5 6 7 8 9 10