On Monday, 6 June 2022 at 06:56:46 UTC, Ola Fosheim Grøstad wrote:
On Monday, 6 June 2022 at 06:14:59 UTC, Sebastiaan Koppe wrote:
Those are not places where you would put an assert.

The only place to put an assert is when *you* know there is no recovery.

No, asserts are orthogonal to recovery. They just specify the assumed constraints in the implementation of the algorithm. You can view them as comments that can be read by a computer and checked for that specific function.

I guess an informal way to express this is:

*Asserts are comments that you would need to make when explaining why the algorithm works to another person (or to convince yourself that it works).*

As far as unnecessary asserts, it would be nice to have something more powerful than static assert, something that could reason about runtime issues that are simple and issue errors if it could not establish it. E.g.:
```
int i = 0;
…later…
i++;
…much later…
compiletime_assert(i>0);
```

        • Re: Comparing Ex... Steven Schveighoffer via Digitalmars-d-learn
          • Re: Comparin... Steven Schveighoffer via Digitalmars-d-learn
          • Re: Comparin... kdevel via Digitalmars-d-learn
            • Re: Com... Steven Schveighoffer via Digitalmars-d-learn
              • Re:... kdevel via Digitalmars-d-learn
              • Re:... Steven Schveighoffer via Digitalmars-d-learn
              • Re:... Ola Fosheim Grøstad via Digitalmars-d-learn
              • Re:... Ola Fosheim Grøstad via Digitalmars-d-learn
              • Re:... Sebastiaan Koppe via Digitalmars-d-learn
              • Re:... Ola Fosheim Grøstad via Digitalmars-d-learn
              • Re:... Ola Fosheim Grøstad via Digitalmars-d-learn
              • Re:... Steven Schveighoffer via Digitalmars-d-learn
              • Re:... Ola Fosheim Grøstad via Digitalmars-d-learn
              • Re:... Ola Fosheim Grøstad via Digitalmars-d-learn
              • Re:... Steven Schveighoffer via Digitalmars-d-learn
              • Re:... Ola Fosheim Grøstad via Digitalmars-d-learn
              • Re:... Ola Fosheim Grøstad via Digitalmars-d-learn
              • Re:... kdevel via Digitalmars-d-learn
  • Re: Comparing Exceptions and ... frame via Digitalmars-d-learn

Reply via email to