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

Manu turkeyman at gmail.com
Mon Jul 30 21:12:53 UTC 2018


On Mon, 30 Jul 2018 at 13:25, Walter Bright via Digitalmars-d
<digitalmars-d at puremagic.com> wrote:
>
> On 7/30/2018 9:45 AM, Manu wrote:
> > Sure it 'works', but it's an annoying point of friction, and it
> > doesn't need to be that way.
>
> You can reduce it to:
>
>      mixin(cppNamespace("ns", "void foo();"));
>
>
> >> You haven't explained why you can't just move the namespace ns declarations in
> >> one file together.
> >
> > Are you serious?
>
> Yes, please explain why you can't coalesce the namespace declarations in one C++
> file into one namespace declaration.

We're talking about multiple C++ files, not one.
Problems arise when you import 2 modules since the namespaces collide.
You need to disambiguate with the D module identifier anyway, which
self-defeats the whole design! The C++ namespaces are redundant.
They just lead to user confusion, and more tedious metacrobatics when
scanning for things. No scanning meta supports recursing into C++
namespaces.

> > When torrents of people complain, you can send every single one of
> > them to me, tell me "I told you so", and I'll eat my hat.
>
> Apologies don't pay the bills. C++ is full of such stuff, and the bill for it is
> staggering.

I'm suggesting there will not be any such bug report. The result will
be simpler and more intuitive, and there will be less complaints, not
more.

We don't want C++'s namespaces in D. I have no idea why you do... cus
you go on and on about how complex and horrible they are. And now we
have a thing that's not like C++ namespaces, and also not like normal
D code (where normal D modules would be absolutely fine).
I agree with you completely... I don't want C++ namespaces in D. I
also don't want _anything like them_. We're all happy with the D
module system, that's how we want to organise our code. Please let us
organise our code using the D module system.


More information about the Digitalmars-d mailing list