Why is D unpopular?

forkit forkit at gmail.com
Sun May 22 02:51:24 UTC 2022


On Saturday, 21 May 2022 at 03:05:08 UTC, Walter Bright wrote:
> On 5/19/2022 11:40 PM, Tejas wrote:
>> Isn't the advice to use `enforce` for handling/verifying input 
>> in release builds and `assert` for development builds though?
>> Yeah, it's violating DRY if a particular check needs to be 
>> done in both development and release, but then one can skip 
>> the `assert` and just do `enforce`, no?
>
> Asserts are *not* for validating program input. Please do not 
> use them for that. They are for checking that the program's 
> logic is correct. If an assert is tripped, it is a bug in the 
> program, not a problem with user input.

I don't agree, that 'tripping an assert' == 'a bug in your 
program'.

It may well ward off a potential bug (by asserting before hand, 
to prevent a bug).

But I can do this with exceptions too.

The main reason I'd chose to catch exceptions, rather than an 
assert, is in a situation where I want to *both* test and handle 
'expected' conditions.

I'd use an assert where I don't want to handle any 'unexpected' 
conditions.

I rarely use assert in any case, as the software I develop is 
very user friendly ;-)

But this argument is like the argument of whether you should use 
your left foot, or your right foot to brake.




More information about the Digitalmars-d mailing list