Import proposals (Discuss)

Regan Heath regan at netwin.co.nz
Sun Jul 9 19:25:45 PDT 2006


On Mon, 10 Jul 2006 02:01:31 +0000 (UTC), John Reimer  
<John_member at pathlink.com> wrote:
> In article <e8s9fk$2e3f$1 at digitaldaemon.com>, Tom S says...
>>
>> Regan Heath wrote:
>>> Something that has just occured to me WRT "Part-C" of my idea.. the
>>> restriction of allowing only one module is probably un-necessary if we
>>> assume a rule;
>>>
>>> * If a module is a single word i.e. "mylib" it comes at the start of an
>>> import statement, eg.
>>>
>>>   import mylib;
>>>
>>> or
>>>
>>>   import mylib,my.other.lib.copyFile;
>>>
>>> etc.. and never after a "," eg.
>>>
>>>   import my.other.lib.copyFile,mylib;
>>>
>>> (where "copyFile" is a symbol in "my.other.lib" and "mylib" is not)
>>>
>>> So, this allows multiple modules in the same import statement even
>>> allowing you to import them into the same named scope, some examples:
>>>
>>>   import my.other.lib.copyFile,deleteFile,your.lib.moveFile;
>>>
>>> imports "copyFile" and "deleteFile" from "my.other.lib" and "moveFile"
>>> from "your.lib".
>>>
>>>   import my.other.lib.copyFile,deleteFile,your.lib.moveFile as file;
>>>
>>> imports "copyFile" and "deleteFile" from "my.other.lib" and "moveFile"
>>> from "your.lib" into named scope "file".
>>>
>>> Thoughts?
>>
>> Sorry, but I don't like it. I bet that every second coder new to the
>> language would get totally confused by it.
>>
>>
>
> I agree with, Tom.  Too confusing.

Really? :(

I mean, I don't see importing specific symbols as something a 'new' coder  
would do.. For example 'in my imaginary world' I see mr new coder...

1. starting with hello world, eg.

--[helloworld.d]--
import std.stdio;
void main()
{
   writefln("Hello World");
}

2. Moving on to import his own module eg.

--[mymod.d]--
void sayHello() { writefln("Hello World"); }

--[helloworld.d]--
import std.stdio,mymod;
void main()
{
   sayHello();
}

which will all work fine, no problems.

3. It's when he starts to think.. "I just need writefln why not code it  
like this" ..

--[mymod.d]--
void sayHello() { writefln("Hello World"); }

--[helloworld.d]--
import std.stdio.writefln,mymod;
void main()
{
   sayHello();
}

that he'll get an error.

In short, it's only a problem if you import a specific symbol in the same  
statement as a module which has no package (no "." in the module  
name/path/whatever)

Regan



More information about the Digitalmars-d mailing list