strange behavior of by-value function arguments in postcondition

deadalnix deadalnix at gmail.com
Fri Sep 3 00:23:48 UTC 2021


On Thursday, 2 September 2021 at 13:33:34 UTC, Meta wrote:
> On Wednesday, 1 September 2021 at 06:14:27 UTC, bauss wrote:
>> Pre/post conditions _are_ assert statements tho. User 
>> validation should be done using exceptions, not asserts.
>
> The fact that they are assert statements is an implementation 
> detail. The point of pre/post conditions is to enforce that 
> certain properties of the function hold, and assertions are 
> just how the language happens to implement that.

More specifically, the in condition is a contract that concern 
the caller - in some way the user of the code. You'll not that, 
because the in condition is a failure of the caller, then what 
DMD does is wrong - the contract needs to be at the call site. 
You might that this is just an implementation detail, but it is 
in fact very relevant for contract on polymorphic functions, 
which will do the wrong thing with the current implementation.

The out condition is a contract that concern the callee. So in a 
way, it doesn't concern the user, except to the extent that it 
provides documentation and what to expect from the callee.

Because this topic was specifically about out contracts, the 
claims were not widely off base.


More information about the Digitalmars-d mailing list