Is there any good reason why C++ namespaces are "closed" in D?

Manu turkeyman at gmail.com
Tue Jul 31 16:23:55 UTC 2018


On Tue., 31 Jul. 2018, 3:40 am Jacob Carlborg via Digitalmars-d, <
digitalmars-d at puremagic.com> wrote:

> On 2018-07-31 10:12, Manu wrote:
>
> > Given your favourite example:
> > ----
> > module a;
> > extern(C++, ns) void foo();
> > ----
> > module b;
> > extern(C++, ns) void foo();
> > -----
> > module c;
> > import a, b;
> > foo(); // error: ambiguous
> > ns.foo(); // error, ambiguous (obviously)
> > a.ns.foo(); // naturally, this works... it's the D module that
> > correctly organises the symbol. 'ns' is worthless here
>
> This works:
>
> a.foo();
>
> You don't need "ns" in between the module name and the function.
>

Right... But did you miss the point? The D module does the organisation (as
you show). The ns offers nothing and creates other kinds of problems.
Just because name resolution traverses the namespace (in simple cases),
there is an entire language of complexity that interacts with that name
lookup, and as far as I know, it has never proven useful, but rather, only
complicated and annoying leading to boilerplate and hacks in certain
situations. (ie, this thread exists and many others)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20180731/199696ca/attachment.html>


More information about the Digitalmars-d mailing list