www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - adding static return?

reply Xavier Bigand <flamaros.xavier gmail.com> writes:
I thought it could be nice to have a static return.

My Idea is to remove unnecessary bracket encapsulation made with some 
static if statements.

It will works like this :

module xxx.opengl;

import buildSettings; // contains some global constants

static if (renderMode == directX)
   return;

...


So there will no more need to scope the module code and indent it.

Is it a good idea?
Mar 03 2014
next sibling parent "Stanislav Blinov" <stanislav.blinov gmail.com> writes:
I don't get it. That should be a static assert, not static if. 
Why would you even add into your build order a module that will 
never be actually compiled?

If anything, static assert will prevent dead imports while such 
"static return" will silently swallow them.

How would you propose handling module constructors and 
module-scope variables in presence of such return?
Mar 03 2014
prev sibling parent "Nicolas Sicard" <dransic gmail.com> writes:
On Monday, 3 March 2014 at 23:27:42 UTC, Xavier Bigand wrote:
 I thought it could be nice to have a static return.

 My Idea is to remove unnecessary bracket encapsulation made 
 with some static if statements.

 It will works like this :

 module xxx.opengl;

 import buildSettings; // contains some global constants

 static if (renderMode == directX)
   return;

 ...


 So there will no more need to scope the module code and indent 
 it.

 Is it a good idea?
This is just to avoid brackets and the compulsion of indenting inside them, isn't it? ;-) Version blocks can be used with colons (see http://forum.dlang.org/thread/lep2p3$2765$1 digitalmars.com for a caveat). May be this syntax could be extended to module-level static ifs. D would look more and more like Python...
Mar 04 2014