On Thursday, 19 February 2015 at 12:16:18 UTC, Mike Parker wrote:
On Thursday, 19 February 2015 at 10:17:47 UTC, Dicebot wrote:
Most practical approach I am currently aware of is wrapping
actual implementation (in most restrictive version):
I really like mixins for this sort of thing.
```
enum signature = "void longFunction()";
version( Static )
enum sig = "static " ~ signature;
else
alias sig = signature;
enum funcBody =
q{{
import std.stdio : writeln;
writeln( "Hi there!" );
version( Static ) writeln( "I'm static!" );
}};
struct Mixed {
mixin(sig ~ funcBody);
}
void main() {
version( Static ) Mixed.longFunction();
else {
Mixed m;
m.longFunction();
}
}
```
@OP: By using a token string (q{}) for funcBody rather than a
WYSIWYG string (r"" or ``), you can still get syntax
highlighting in your editor.
Based on your example, bye bye readibility. It is like writing
rocket taking off procedures.
People are complaining about different parts of D languages some
structures (there are good ones, there are bad ones), but
unfortunately, bad ones are continuously ignored in the name of
trying to reach the language a stability.