No need for version expression is a lie

Walter Bright newshound2 at digitalmars.com
Thu Aug 24 23:51:52 UTC 2023


On 8/24/2023 11:04 AM, Adam D Ruppe wrote:
> But, I'd point out that this kind of thing is even worse than not having the 
> `else static assert(0)` branch at all. Suppose you wrote it like this in the 
> first place:
> 
> ```
> version(Windows)
>    enum x = 8;
> version(linux)
>    enum x = 8;
> 
> // somewhere else
> 
> version(Windows)
>    enum y = 9;
> version(linux)
>    enum y = 7;
> ```
> 
> You port it to AdrOS.
> 
> ```
> import that;
> void main() {
>     auto thing = x;
> }
> ```
> 
> You now get a nice error: undefined identifier "x". *as you use it*, the 
> compiler tells you it is missing and you know to go fix it. Then later, when you 
> use y, you again get undefined identifier and you go back and add it. It is 
> incrementally ported - always compiling the core, with more advanced test cases 
> failing until you fill in those features.

If you want to do it that way, that's ok. I just want to head off the 
commonplace use of defaults. I also like, when I've ported to a new OS, knowing 
where all the OS specific tweaks need to go, up front. Getting an "undefined x" 
doesn't tell me where the x needs to be defined.

But your method is still workable.



More information about the Digitalmars-d mailing list