Arbitrary abbreviations in phobos considered ridiculous

Steven Schveighoffer schveiguy at yahoo.com
Fri Mar 9 16:59:56 PST 2012


On Fri, 09 Mar 2012 19:32:06 -0500, David Nadlinger <see at klickverbot.at>  
wrote:

> On Friday, 9 March 2012 at 23:39:25 UTC, Steven Schveighoffer wrote:
>> I want to stress again the difference between C++'s namespaces, and D's  
>> module import mechanism.  In C++, you *deliberately* pull a namespace  
>> into your scope (and usually only in the implementation file, which  
>> doesn't affect any other implementation files), whereas in D, a  
>> standard "import std.datetime" *automatically* pulls its namespace into  
>> your scope, and any public imports it has made.
>
> To be honest, I don't quite see the big difference here. Just as you can  
> only #include a »namespaced« file without using a using directive, you  
> can »static import« a module in D. You seem to be arguing that we  
> shouldn't encourage use of these features (cf. the std.log discussion),  
> but I can't quite follow you there.

The big difference is, the most straightforward and most exemplified  
import syntax is:

import modulename;

So to argue this is not the default syntax, or not the most desirable/used  
syntax is just plain invalid.

In contrast, C++'s import syntax is:

#include "modulename.h"

which does not import any namespaces into your scope.

> Why would _not_ using static and selective imports be desirable? Don't  
> we generally discourage people from write »using namespace std« in C++  
> or »import *« in Python as well? (I'm aware that the D module system is  
> different, but the general idea is the same)

I don't think we should make the default the most conflicting or difficult  
to use method.  For example, to say:

"always import log using:

import log = std.log"

Is not as good as just not having to say that (i.e. import std.log like  
you would any other module).  I remember Tango had a couple of modules  
like that, and I thought it was pretty confusing.

That doesn't mean you can't utilize those facilities (and I *don't*  
discourage them).  I just don't think it should be a barrier to usage.

-Steve


More information about the Digitalmars-d mailing list