Adding a new design constraint to D

forkit forkit at gmail.com
Tue Jun 14 23:28:26 UTC 2022


On Tuesday, 14 June 2022 at 12:00:29 UTC, The Zealot wrote:
>
> I don't think calling it a workaround is even correct.
> _class private_ would actually be the workaround. Just to put 
> multiple classes inside one file that should conceptually not 
> be in the same file in the first place.

why would you "put multiple classes inside one file that should 
conceptually not be in the same file in the first place. "?

that makes no sense??

Also, I come from a world where if something should be private, 
you should be able to declare it as private. It's a clear 
principle in the languages I use.

private is design tool to aid encapsulation, and makes it hard to 
accidently get it wrong.

it's a feature I use all the time, for (primarily) those reasons 
just stated.

if that feature we're removed from C#, we'd be in deep shi$. the 
barrier of encapsulation would be widened, not lessened, and 
accidental mistakes will occur all the time.

without the feature I'm suggesting, you end up with what you 
already have in D.

That is, you cannot use private to aid encapsulation *within* a 
module, nor can you use it prevent you (or others) from getting 
it wrong. since it doesn't exist!

you have to rely on yourself in D, to 'just not do it' - (it's a 
C like mentality - which some are truly eager to protect as an 
important part of the indentity of the D programmer). I get it, 
but that just doesn't scale very well.

you can't rely on every programmer on your project to 'just not 
do it'.

The problem, once you want to scale software design, is not 
'having' scope level private, it's 'not having it' - and the 
(primary) problems are as I've highlighted above.

There is no downside to better encapsulation within a module, nor 
is there any downside to preventing accidental mistakes - unless 
you want neither of these things.

I'd also like to be able to better enscapsulate ideas that 
already exist within a module, by being able to spread that 
module over more than one file. but that's a topic for another 
thread ;-)



More information about the Digitalmars-d mailing list