Import concerns revisited

Derek Parnell derek at nomail.afraid.org
Wed Jul 12 01:17:01 PDT 2006


On Wed, 12 Jul 2006 10:45:09 +0300, Georg Wrede wrote:

> Derek Parnell wrote:
>> On Wed, 12 Jul 2006 09:25:50 +0300, Georg Wrede wrote:
>>>Regan Heath wrote:
>>>
>>>>import std.stdio as io;
>>>>
>>>>writefln("");    //error
>>>>io.writefln(""); //ok
>>>>
>>>>in that this syntax allows the compiler to _not_ import into the  
>>>>2ndary namespace and _instead_ into the named one, instead of doing 
>>>>both,  which is what appears does/will happen using 'alias'. I prefer this.
>>>
>>>Exactly!
>>>
>>>And this is *very important*.
>> 
>> Why?
> 
> Several reasons.
> 
>   - The syntax looks explicit enough for the programmer to honestly 
> assume that the only import is to the specified namespace.

Hmmm ... I read "import std.stdio as io" as saying import std.stdio and
from here on in the text of this module, when 'io' is used assume that
'std.stdio' was meant instead. In other words, I see this as saying that
'io' is an optional, alternative reference to 'std.stdio'. I don't read
'io' as being a namespace, but just an alias for std.stdio.

However if the synatx was "import std.stdio into io" that would make me
think of 'io' as a namespace into which the stuff in std.stdio was placed
for look up.

>   - Doing stuff behind the back is Bad Manners.

Automatically looking into the imported files for matching names is bad
manners? Not for me it isn't. In fact it seems down right neighbourly.

>   - Importing to both would not alleviate the problem of namespace 
> pollution.

And by "namespace pollution" you are referring to the increased possibility
of duplicating names in the same lookup scope level, right? Of course it
wouldn't but that's not what it was trying to do.

>   - Who'd understand the error messages about name clashes?

Messages like ...

  myfile(44): Cannot find an accessible matching function 'foo'.

>   - Any outsider would really consider this a grave beginner bug from 
> the compiler writer.

I don't think there is much evidence of that yet, but may by I'm not an
"outsider" (read?: experienced C++/C#/Java user?). In any case, if it's
behaviour is correctly documented one can simply get educated instead of
assuming a beginner compiler writer.

-- 
Derek
(skype: derek.j.parnell)
Melbourne, Australia
"Down with mediocrity!"
12/07/2006 5:54:32 PM



More information about the Digitalmars-d mailing list