[Issue 13605] Add ability to `version` a module declaration

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sun Oct 12 06:49:52 PDT 2014


https://issues.dlang.org/show_bug.cgi?id=13605

--- Comment #2 from Mike <slavo5150 at yahoo.com> ---
(In reply to Ketmar Dark from comment #1)
> what to do with this code:
> 
>   version(Posix) module mod;
>   int n;
> 
> should it be rejected, should compiler build default module name (as it does
> now), or something else?

What does the compiler do now if the module declaration is missing?  This
enhancement shouldn't change anything.

> 
> 'version' is not '#ifdef', and it's bad suited for such usage. i suggest to
> use wrapper module and platform-specific modules. like this:
> 
>   === port.d ===
>   module port;
>   version(Posix) public import port.posix;
>   else version(Win32) public import port.win32;
>   else version(Win64) public import port.win64;
>   else static assert(0, "no porting was done for this platform!");

This introduces a new namespace.  It's not a deal-breaker, but it's
undesirable.

> 
> note: i suggest to avoid such public imports, though. it's better to write
> wrappers in "port.d" which calls platform-specific `foo()`. there are some
> problems with public imports with renamings and such.

Agreed, but this quickly turns into `version` hell.  It doesn't scale well. 
Have you seen some of the druntime code?  Again, it's not a deal-breaker, but
it's undesirable.

This enhancement wouldn't prevent any of the alternatives you've mentioned.  It
does no harm.  One of the arguments in favor of adding attributes to module
declarations is that module declarations don't need to be anything special. 
The same argument can be made in favor of this enhancement.  It's consistent
with the language, and provides designers some options that currently don't
exist.

--


More information about the Digitalmars-d-bugs mailing list