`restricted` member variables
Ola Fosheim Grøstad
ola.fosheim.grostad at gmail.com
Tue Jun 21 07:26:50 UTC 2022
On Tuesday, 21 June 2022 at 01:20:27 UTC, Mike Parker wrote:
> Targeted invariants would be nice. Not a must have, probably a
> niche case, but definitely nice to have.
The intent is to give the compiler a constraint, so the
assumption that the compiler doesn’t have access to the full
constraint is the same as assuming that the programmer doesn’t
know what he is doing. The right thing to do is to help the
programmer and reject such illdpecified constraints.
If you specify preconditions/postconditions then the exit check
should be considered part of the assumed precondition and the
asserted postcondition. If you allow the class invariant to be
hidden from the compiler then you mess up the preconditions.
Asserts only add information that is redundant and would be
removed by a perfect static analysis. If that isn’t possible then
either the invariant/assert is badly written or the program is
wrong.
More information about the Digitalmars-d
mailing list