[fpc-pascal] Optional param modifier

Ryan Joseph ryan at thealchemistguild.com
Mon Apr 15 01:19:11 CEST 2019



> On Apr 14, 2019, at 7:08 PM, Martin Frb <lazarus at 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




More information about the fpc-pascal mailing list