<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Sun, Oct 28, 2018 at 9:30 PM unprotected-entity via Digitalmars-d <<a href="mailto:digitalmars-d@puremagic.com">digitalmars-d@puremagic.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Sunday, 28 October 2018 at 05:28:31 UTC, Mike Parker wrote:<br>
><br>
> You can make the same mistake inside the class:<br>
><br>
> class Foo {<br>
> private int x;<br>
> void increment() {...}<br>
> ...<br>
> void doSomethingInternal() { x++; }<br>
> }<br>
><br>
> How is making that mistake outside of that final curly brace <br>
> any different or any worse? It's all in the same file.<br>
<br>
Except, that (I assume) a module in D is meant to be more than <br>
just a single class.<br>
<br>
If that's not the case, then my argument is irrelevant.<br>
<br>
If it is the case, then you presumably would have a great deal <br>
more code in your module, than you would in a single class. <br>
Hence, greater likelihood of mistakingly<br>
accessing a private member of some class defined within the <br>
module, somewhere.<br>
<br>
In any case, it does undermine the principle of encapsulation <br>
(assuming you agree that a class deserves to be a unit of <br>
encapsulation).<br>
<br>
In, it's nothing more than a convenient hack, really.<br>
<br>
There is not a third option here.<br>
<br></blockquote><div>The advantage of the Way D does things is that you don't have to put your data into a class and instantiate it in order to have encapsulation.</div><div>In C++ for instance often data is put into a class just to have encapsulation, this has a cost in resources as well the complexity of program.<br>In D any data that there only needs to be one copy of and lasts the lifetime of the program belongs in a module rather than a class.<br>In practice this tends to mean less classes, and less of the work done inside classes.<br>D source code can feel inside out compared to C++ source code.<br> <br> </div></div></div>