Current way of doing conditional compilation is nice, but it is very reminiscent of C's #ifdefs, which when used with native blocks is kind of cumbersome.
From all languages I've seen D seems to handle conditional compilation the best. For checking compiler flags (like fut's -D) it uses version blocks, which are used in this way:
version(WINDOWS) {
// Some code
}
Which lands itself nicely with chaining code blocks
version(LINUX) if (somevar) {
// Some other code
}
My proposal is to instead of current conditional compilation blocks introduce something similar to D's version statement.
Example:
// not sure about statement name though
flag(JS) native {
// native js only code
}
flag(JAVA) {
// java related code
} else {
// code for everything else
}
flag(CS) {
// c# code
} else flag(CPP) {
// c++ code
} else {
// everything else
}
And since it's code block based it lands nicely with both native blocks and out of box elseif support.
More about conditional compilation in D: https://dlang.org/spec/version.html (there's a bunch more interesting features)
Related: #142
Current way of doing conditional compilation is nice, but it is very reminiscent of C's
#ifdefs, which when used withnativeblocks is kind of cumbersome.From all languages I've seen D seems to handle conditional compilation the best. For checking compiler flags (like fut's
-D) it usesversionblocks, which are used in this way:Which lands itself nicely with chaining code blocks
My proposal is to instead of current conditional compilation blocks introduce something similar to D's
versionstatement.Example:
And since it's code block based it lands nicely with both native blocks and out of box elseif support.
More about conditional compilation in D: https://dlang.org/spec/version.html (there's a bunch more interesting features)
Related: #142