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

Daniel N via Digitalmars-d digitalmars-d at puremagic.com
Tue Jan 3 02:18:57 PST 2017


On Monday, 2 January 2017 at 21:23:19 UTC, Andrei Alexandrescu 
wrote:
>
> No worries, I'll make a pass (a rewrite, really) taking all 
> feedback into account.

Are all the proposals mutually exclusive? When it comes to 
declarations, the DIP actually won me over! However I was hoping 
for it to solve a different issue inside the body with local 
imports. I tend to write short helper functions, with the result 
that in the common case, an imported symbol is often used only 
once per function.

Currently I consider it good style to list all imports in the 
beginning of a scope, but based on past experience with C89, this 
is not entirely optimal, however Timon Gehr's proposal could 
solve it.

import and directly invoke:
import std.traits : isArray(...)

=======================================================
[Proposed Style - analogous to C99]
body
{
   static if(...)
     import std.range : zip(...);
   static if(import std.traits : isArray(...)))
     import std.range : join(...);
}
=======================================================
[Old Style - analogous to C89 - Suffers from "unused" imports]
body
{
   import std.range : zip, join;
   import std.traits : isArray;

   static if(...)
     zip(...)
   static if(isArray(...)))
     join(...)
}
=======================================================
[Alternate Style - Suffers from DRY and can't limit scope of 
isArray]
body
{
   import std.traits : isArray;

   static if(...)
   {
     import std.range : zip;
     zip(...);
   }
   static if(is(isArray(...)))
   {
     import std.range : join;
     join(...);
   }
}

C89 vs C99 style I was referring to if it wasn't clear.
=======================================================
[C89]
void foo(void)
{
#ifdef ... /* needed to silence unused variable warnings */
   int x;
#endif
... lots of code ...
#ifdef ...
   x = bar();
#endif
}

[C99]
void foo(void)
{
#ifdef ...
   int x = bar();
#endif
}
=======================================================



More information about the Digitalmars-d mailing list