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

Walter Bright newshound2 at digitalmars.com
Sun Jul 29 07:37:08 UTC 2018


On 7/28/2018 11:06 PM, Nicholas Wilson wrote:
> Then again I don't see any (non philosophical/compiler front end internal) issue 
> why you can't reopen a namespace. D is supposed to be pragmatic, after all.

Consider if a template reopens a namespace and throws a few more overloads in 
it. Then, what's in the namespace is dependent on which expansions are done, in 
which order. Throw in the inevitable circular references. Do people write code 
like that? Sure as shootin', they do, and they demand that it work, and file 
lots of bug reports about the erratic behavior.

Next, consider a function body throwing a few more overloads in. Now, if the 
function body is compiled or not (and the compiler tries to avoid compiling 
bodies unless it has to) affects code that is outside of the function.

C++ is full of stuff like that. The difference is, when code fails in some 
bizarre way, programmers blame themselves and throw money at Scott Meyers to 
educate them on how to avoid writing such code. For D, they blame me.

The last time we fixed scope lookup to make it more complicated was with 
imports, and that took YEARS to sort out.

So I'm a little reluctant to add features that will result in a rat's nest of 
problems I can neither explain nor fix, then someone will add 4000 
incomprehensible lines to fix 2 cases and add 5 or 6 bizarre regressions in the 
process and people complain the compiler is unstable. :-)


More information about the Digitalmars-d mailing list