checkedint call removal

Tofu Ninja via Digitalmars-d digitalmars-d at puremagic.com
Thu Jul 31 07:51:15 PDT 2014


On Thursday, 31 July 2014 at 07:00:01 UTC, Walter Bright wrote:
> 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.

But that is verifying that the input is sort-able....

All I am saying is that the idea that assert should not be used 
to verify input makes no sense at all. Every program takes in 
input and once a little bit is in, anything derived from that 
input is also input.

...

Also this thread has made me firmly never want to trust assert 
again... I have actually been going though my projects and 
removing them now because I don't trust them any more...


More information about the Digitalmars-d mailing list