DIP61: Add namespaces to D

Andrej Mitrovic via Digitalmars-d digitalmars-d at puremagic.com
Sun Apr 27 02:04:30 PDT 2014


On 4/27/14, Walter Bright via Digitalmars-d <digitalmars-d at puremagic.com> wrote:
> On 4/27/2014 1:16 AM, Andrej Mitrovic via Digitalmars-d wrote:
>> There's a need for scoping symbols other than in modules,
>
> What is that need?

Here's some examples from Phobos:

std.uni.unicode is a lowercase-named struct because it's supposed to
be used as a namespace:

-----
auto ascii = unicode.ASCII;
-----

And here's std.datetime using a similar trick:

-----
/++
    Effectively a namespace to make it clear that the methods it contains are
    getting the time from the system clock. It cannot be instantiated.
 +/
final class Clock
-----

I've seen other libraries use this sort of trick. E.g. the D1 Harmonia
GUI library, but I'm pretty sure I saw it in some D2 libraries.

>> Not unless we have a really solid DIP.
> What's wrong with the DIP?

It's barely 10 sentences long, I've seen forum posts longer than this.
It's supposed to be solid, with lots of example code, and also any
drawbacks or potential conflicts being listed (you list none at all).
It doesn't have a FAQ, links to other competing proposals, etc. And
arbitrary decisions are listed in that DIP without any rationale
whatsoever, e.g.:

- Unlike C++, namespaces in D will be 'closed' meaning that new
declarations cannot be inserted into a namespace after the closing }
=> rationale?

- C++ Argument Dependent Lookup (aka "Koenig Lookup") will not be
supported.  => rationale?

There are other well-written DIPs in there for reference.

>> Idealism aside, modules have some implementation issues right now
>> which force people to use workarounds like named mixins or the above
>> trick, e.g. package access not being propagated up/down a hierarchy.
>
> ??

Here's the report:
https://issues.dlang.org/show_bug.cgi?id=2529

Don's conclusion is what I agree with:
https://issues.dlang.org/show_bug.cgi?id=2529#c1

Quote: "the existing 'package' semantics force you to a flat hierarchy."

Also, package access can be worked around in user-code:
https://issues.dlang.org/show_bug.cgi?id=9381


More information about the Digitalmars-d mailing list