Why is D unpopular?

Dukc ajieskola at gmail.com
Mon May 23 08:46:13 UTC 2022


On Monday, 23 May 2022 at 01:37:09 UTC, Paul Backus wrote:
>
> We actually have this in D, it's just written weirdly:
>
> ```d
> // debug assertion
> assert(condition);
>
> // release assertion
> if (!condition) assert(0);
> ```
>
> It would probably be more intuitive if we could write release 
> assertions as plain `assert`, and use `debug assert` for debug 
> assertions. But the functionality is there.

This is probably the way to go even now. Walter is not convinced 
we should have an option to remove `assert`s from release builds 
in a `@safe` way. So I think the most reasonable convention is:

```d
// debug assertion, use when you suspect performance impact
debug assert(condition);

// regular assertion. Should be on for most applications even in 
release builds, but can be omitted if you're willing to accept 
you don't have memory safety if an assert fails. Should be the 
most common assert.
assert(condition);

// Semi-strong assertion. Should be on for all applications that 
care about memory-safety at all. Use for custom bounds checking 
in `@trusted` or `@system` code.
version(D_NoBoundsChecks){} else if(!condition) assert(0)

// Strong assertion. Always on.
if(!condition) assert(0);
```

In fact, I think this is a good way to go even if Walter changes 
his mind.


More information about the Digitalmars-d mailing list