extern(C++, ns)

Tobias Müller via Digitalmars-d digitalmars-d at puremagic.com
Tue Jan 19 22:35:59 PST 2016


Walter Bright <newshound2 at digitalmars.com> wrote:
> Oh what the hell. I'll answer it one last time:
> 
> 1. C++ has namespaces. They went and invented a whole 'nother thing called 
> modules. Evidently not even they think that modules and namespaces are the same 
> thing.

D has modules, C++ has namespace.
Why do you introduce yet another concept?
You call it named scope but for consumers it behaves like a module...

> 2. Multiple modules cannot have the same name in D. C++ practice is to litter 
> code with namespaces using the same name.

It doesn't help if they are just imported as modules in disguise.

> 3. Modules have ModuleInfos, static constructors/destructors, etc. These do not 
> make obvious sense for namespaces.
> 
> 4. Modules and files have a 1:1 correspondence. This does not work for namespaces.
> 
> 5. "extern (C++) module std" ? Ugh.

Nobody has ever suggested this.
mod and extern should be completely separate.

> 6. Modules do not nest. Namespaces nest.
> 
> 7. Module semantics are independent of where they are imported. Not so for 
> namespaces.
> 
> I.e. if modules were bludgeoned into being namespaces, there would be such a 
> list of special cases and confusions and exceptions and awkward crap you'd be 
> far, far better off having namespace as a SEPARATE feature, because that's what 
> they'd wind up being anyway, even if they were named "modules".

 mod should not imply a C++ namespace and extern(C++, ns) should not
introduce a named scope.
This gives you maximal flexibility with minimal complexity.

You could import symbols from different namespaces to the same module and
you could import symbols from the same namespace to different modules.

Modules and namespaces would be completely independent. 

I'd even count all those points above as arguments _against_ the current
design.

Tobi





More information about the Digitalmars-d mailing list