Import concerns revisited

Bruno Medeiros brunodomedeirosATgmail at SPAM.com
Sun Jul 9 08:56:58 PDT 2006


Walter Bright wrote:
 > [...]
 > [...]

In reply to Walter, Kris, Derek and all who argue on the merits of 
"import X; alias X A;" vs "import X as A;"

Once we have FQN import, which by the looks of it we'll have pretty soon 
(hopefully not with the syntax "static import" though), we'll be able to 
do something which is the first thing I've wanted to do with a FQN 
import: devise a one-line macro of some sort that would FQN import all 
modules of a project. Fortunately, a macro of some sort won't even be 
necessary, we can do it with proper D. Just make a file allfqn.d with 
the contents:

   module allfqn;

   static import mod.foo;
   static import mod.bar;
   static import math.whatever;
   static import math.whatever2;
   static import gfx.whatever;
   static import gfx.whatever2;
   ...

then just do a regular import of all.d in other files:

   module foo;

   import allfqn;

Then the equivalent of:
   import MOD.FOO as BAR;
becomes just:
   alias MOD.FOO BAR;
instead of:
   static import MOD.FOO;
   alias MOD.FOO BAR;

thus this whole debate of one syntax being 2 times wordier than the 
other becomes a non-issue? It has for me, unless there is some other issue.

This behavior of having all project entities(names) automatically 
available by FQN is also how Java and C# work[*], which I think is a 
quite sensible approach. And perhaps this should even be the standard 
among D programs.

[*] How is it in Python and Ruby? (I do not know those languages well) 
Or in any other language you know with such similar structured 
hierarchical namespacing?


-- 
Bruno Medeiros - CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D



More information about the Digitalmars-d mailing list