Question about publishing a useful function I have written

Andre Pany andre at
Wed Jul 15 12:37:21 UTC 2020

On Wednesday, 15 July 2020 at 09:31:27 UTC, Cecil Ward wrote:
> On Tuesday, 14 July 2020 at 23:10:28 UTC, Max Haughton wrote:
>> On Tuesday, 14 July 2020 at 21:58:49 UTC, Cecil Ward wrote:
>>> I have written something which may or may not be novel and 
>>> I’m wondering about how to distribute it to as many users as 
>>> possible, hoping others will find it useful. What’s the best 
>>> way to publish a D routine ?
>>> [...]
>> GitHub is the best place to publish code. Does GDC actually 
>> use the optimization? I tried something like that before but I 
>> couldn't seem to get it to work properly.
> On Tuesday, 14
> ]
> I just tried an experiment. It seems that in release mode 
> assert()s are realised as absolutely nothing at all, and so the 
> _conditions_ in the asserts are not declared. So later 
> generated code does not have the benefit of knowledge of 
> asserted truth conditions in release mode. So in release mode, 
> without these truth conditions being established, the code 
> generated (apart from the asserts’ code) can be _worse than in 
> debug mode_, which seems bizarre, but it’s true.
> for example
>     assert( x < 100 );
>>     if ( x==200 )  // <— evaluates to false _at compile time_
>          {
>          // no code generated for this block in debug mode,
>          // but is generated in release mode
>          }
>>     if ( x < 100 ) // <— no code generated for if-test as cond 
> == true at compile-time

This is by intention. While exceptions are used for resources 
like user input/file system/network,... you use asserts to 
validate your code.
When you publish your code to the world, the assertions have 
"done" their work and there is no need to include them in a 
release build.

Cases where you need asserts in release builds are an indicator, 
that you should have used exceptions instead.

Kind regards

More information about the Digitalmars-d-learn mailing list