> On Apr 14, 2019, at 7:08 PM, Martin Frb <laza...@mfriebe.de> wrote:
> 
> Almost. assert takes the condition itself
> 
> assert(condition_that_must_be_true, 'error message')
> 
> so it would be
>   assert(name<>'', 'requires "name <> ''''" failed for CreateHero');
> 
> You can already insert such asserts yourself. assert exists.
> 
> If you compile with -Sa then they are compiled in the code, otherwise not.

From the compilers perspective isn’t it faster to test the condition first in 
an if statement so the assert function doesn’t get called? Assert tests for 
false also so it needs to invert the test to “name = ‘’” which is not how the 
“requires” statement is worded.

I’ve always made a “fatal” function which works in the opposite direction as 
assert, i.e if the condition is *true* then crash. Don’t know why but that’s 
easier for me to understand. I like the requires section because it works in 
the same logic.


Regards,
        Ryan Joseph

_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to