DIP10005: Dependency-Carrying Declarations is now available for community feedback

Chris Wright via Digitalmars-d digitalmars-d at puremagic.com
Sat Dec 24 17:25:50 PST 2016


On Sat, 24 Dec 2016 17:45:35 +0000, Stefan Koch wrote:
> I just read over the dip, and it is a giant wall of text.
> I cannot really make heads or tails of it.
> Maybe you could write the advantages you hit at in short bullet-point
> form ?

We add the syntax:

with (import foo, bar, baz)
SingleDeclaration

* If you're reading it as source code, you have, usually, 1-3 modules to 
look in for related definitions, instead of lots (plain imports) or one 
(static / selective imports).

* These modules are listed one line up from the declaration (as with 
static imports, unlike selective imports).

* It doesn't look quite as cluttered as static imports.

* It saves a little typing compared to static imports when you use the 
same import twice in one declaration.

* If you need to move this declaration to another module, you don't have 
to worry about imports (provided you assiduously avoid global imports). 
You still have to worry about everything the declaration references from 
the module it was previously defined in.

* The compiler can delay importing the module until you use the 
declaration it's attached to.

* It might be slightly easier to implement in DMD than lazy static / 
selective imports.



We extend that syntax:

with (import foo)
with (import bar, baz)
{
  // multiple declarations
  // possibly other with-import blocks
}

* You have even less typing if you reuse the same import in a lot of 
declarations.

* The compiler can still delay importing the module until you use the 
declaration it's attached to.

* You get to have a fun search through the entire module to try to find 
which modules are imported when reading a declaration, instead of looking 
up one line (first pass on the syntax), looking at the symbol being used 
(static imports), or looking at the top of the file (status quo or 
selective imports).

* That also applies when you try to move a declaration to another module.


More information about the Digitalmars-d mailing list