Is public by default an unsafe default?

NotYouAgain NotYouAgain at gmail.com
Thu May 2 23:02:49 UTC 2024


On Thursday, 2 May 2024 at 17:22:25 UTC, Bastiaan Veelo wrote:
> ...
> Believing that accessibility attributes have any significance 
> regarding security is dangerous.
>
> -- Bastiaan.

People may need to know how something behaves, they don't 
necessarily need to know how it works. Of course, if you want to 
know how it works, there is always a way...

As for accessibility attributes, their purpose is:

"Hiding is for the prevention of accidents, not the prevention of 
fraud" -  Stroustrup, B. 1991. 7be C+ Programming Language, 
Second Edition. Reading, Massachusetts: Addison-Wesley, p. 377

Actually, I read that decades ago. That was justification enough 
for me then, and remains so today.

There is zero reason, that I can surmise, as for why my 
implementation has to be public by default. Having to make it 
private yourself ALL the time, requires discipline. Making it 
private by default requires no effort (well in D it does, since 
you have to remember to add 'private:' to the top of your module).

Hiding implementation and preventing access. That is the 
advantage of private.

The advantage of private-by-default is that you get that 
advantage without any effort on your part (well, except in D of 
course).

Any effort should be going into making something public, not 
making something private.

At least, that is my position. Always has been, almost certainly 
always will be.




More information about the Digitalmars-d mailing list