On Monday, April 30, 2012 05:12:27 Kapps wrote: > On Monday, 30 April 2012 at 01:08:28 UTC, Jonathan M Davis wrote: > > On Sunday, April 29, 2012 17:50:48 Don wrote: > >> * package. I have no idea how a failed Java experiment got > >> incorporated > >> into D. > > > > Really? In some cases, it's indispensable. For instance, once > > std.datetime has > > been split up, it will require it, or it would have duplicate a > > bunch of > > implementation-specific stuff which has no business in the > > public API. > > > > - Jonathan M Davis > > It's entirely dependent on your coding style. For example, when > you look at Phobos you rarely (if ever?) see package functions. > This is because it's entirely module based with a strong degree > of separation between modules. > > However, for someone coming from C#, removing package would be > awful. I personally use package quite often. For the most part, I > stick to one major class per file, and separate things across > library. There are plenty of things that I want other classes in > the package/static-library to use, but don't want to expose to > the public, and thus use package for.
It's a question of how inter-dependent your modules are (which is partly a question of style). If you have a bunch of closely related functionality that should be in separate modules, then it can be quite easy for it to need have stuff which it needs to share but shouldn't be public. This happens much more easily if you follow a style of putting one class per module as you _must_ do in Java and C# but don't have to do in D. Phobos doesn't have all that many types in it (though that's changing as it grows). Historically, it's been (and mostly still is) a collection of free functions which have been organized in modules with related functions sharing modules. However, free functions tend to be quite independent. At most, they may share some private helpers. They rarely need to share stuff across modules. On top of that, Phobos has historically avoided creating sub-modules in favor of a flat hierarchy (though that's starting to change) The result of this is that package hasn't been needed in Phobos. I suspect that Don's take on things comes from that (and he probably hasn't needed package in his own stuff either). But I don't think that it's very hard at all to come up with examples where package level access can be invaluable. - Jonathan M Davis
