checkedint call removal

Walter Bright via Digitalmars-d digitalmars-d at puremagic.com
Thu Jul 31 00:00:04 PDT 2014


On 7/30/2014 10:49 PM, Tofu Ninja wrote:
> On Thursday, 31 July 2014 at 05:05:33 UTC, Walter Bright wrote:
>> On 7/30/2014 8:09 PM, Tofu Ninja wrote:
>>> When is the appropriate time to use an assert? If an assert
>>> should not be used on input, then any thing that can't be
>>> statically known is considered an input and anything that is
>>> derived from an input is also an input... so when can we use an
>>> assert? The only things left it seems are things know at compile
>>> time and at that point what is the the point of having assert
>>> when we have static assert...
>>
>> Asserts are used to verify the logic of your code is correct:
>>
>>    x = y + y;
>>    assert(x == 2 * y);
>
> If x and y are floats and y is nan then that assert will fail.....
> That assert is implicitly verifying that the input y is not nan,
> that is a misuse of assert by your definition.

If it pleases you, prepend int x,y; to the snippet.


> Any assert made on a piece of data that is derived from inputs is
> verifying some aspect of that input, which is a misuse of assert
> according to the current definition. So I still state that
> according to current definitions, assert should only be used on
> things that are known at compile time. What is the use of that?

For example, you can have a sort function, and then at the end assert that the 
output of the function is sorted.



More information about the Digitalmars-d mailing list