"bearophile" <[email protected]> wrote in message news:[email protected]... >I have shown this little program to some of my friends that program in >Java/C#: > > class Foo { > private int x; > } > void main() { > Foo f = new Foo; > f.x = 5; > } > > > When I say them this code compiles with D2 they usually tell me that the > compiler has a bug.
There's probably a whole bunch of features you could do the same with. 2 public classes in one file for example. FWIW Delphi has the same 'module' (unit in Delphi speak) level visibility. And in 10 years of using it I've never had a problem with it. There needs to be some way to make some features visible between interdependant classes or else you end up having to make things public that only needed to be public to a few classes. It would reduce encapsulation in a bad way because you end up having to expose things to users of the module or library that they dont need to see. Because it's either visible to everyone or visible to no-one. So anyone who recoils at such a feature does so for ideological reasons not from experience in my opninion. But really whats needed is 'class private' and 'module private'. Then the idealists and the pragmatists will both be happy. :-)
