Good examples of version() algebra in real code

Petar Petar
Mon May 22 11:46:10 UTC 2023


On Monday, 22 May 2023 at 11:23:32 UTC, Adam D Ruppe wrote:
> On Monday, 22 May 2023 at 08:21:50 UTC, Walter Bright wrote:
>> Personally, I like to make the core code version-independent 
>> and OS-independent and hide the variances in separate modules. 
>> Isn't foo() clean looking?
>
> http://dpldocs.info/this-week-in-d/Blog.Posted_2023_02_20.html#static-assert-patterns-arguably-harmful-for-porting

I agree with you that having the option of using run-time guards 
like  `assert(0)` / `throw new NotImplementedEx()` and even using 
empty declarations at compile-time is very convenient in practice 
to get going with a port. On the other hand, I also find a great 
amount in being able to get an almost complete list of things 
that I need to fix at compile-time in terms of planning my work. 
Based on your blog post it would seem that two approaches are 
opposite to each other, but I think we should find a way to have 
our cake and eat it.

A better solution (in that it works with the existing code using 
`static assert`s) would be having fully lazy compilation model 
further along the lines of `dmd -i`:
starting from set of root symbols (e.g. `main`, `unittest` when 
unit tests are enabled, and functions explicitly marked as 
`export`) the compiler should semantically analyse only the 
declarations which are referenced (directly or indirectly) from 
the root set. That way, if any symbol (be it `enum`, `struct`, 
function, etc.) is not referenced, it won't analysed and the 
`static assert` won't be hit.


More information about the Digitalmars-d mailing list