`restricted` member variables

Ola Fosheim Grøstad ola.fosheim.grostad at gmail.com
Wed Jun 22 08:16:26 UTC 2022


On Wednesday, 22 June 2022 at 08:00:41 UTC, claptrap wrote:
> Maybe go through github / bugzilla whatever, find some **real** 
> examples of bugs it would have prevented. I think you'll have a 
> tough time, because if it did help prevent bugs more people 
> would be like "oh yeah that would be really useful".

It is useful when building your model. That is too obvious a 
point to argue: Start out by making everything maximally 
constrained, then loosen up (reluctantly) when you have no other 
option. The resulting model will be much better than if you just 
can change things from the outside. The reason for this is that 
good encapsulated code will produce a higher line count, and most 
programmers aim for a low line count (subconsciously or 
deliberately).

It is also invaluable when you are dealing with multi-threaded 
code that does dangerous things related to memory, as such bugs 
are very difficult to pin-point.

It is quite useful to make a class/struct within a class fully 
encapsulated when you create challenging data structures. E.g. 
anything lock-free.




More information about the Digitalmars-d mailing list