[fpc-pascal] Optional param modifier
ryan at thealchemistguild.com
Sun Apr 14 16:05:44 CEST 2019
> On Apr 14, 2019, at 3:15 AM, Sven Barth via fpc-pascal <fpc-pascal at lists.freepascal.org> wrote:
> Your idea requires exceptions as well. The compiler is not capable checking whether valid entries are passed in at compile time except for simple, constant cases, so runtime checks are needed and the only way to abort something is by exceptions.
My idea didn’t require the procedure to exit so I don’t see where an exception would be needed. It just says if a param was flagged you would need to check for nil before dereferencing other you get a compile time error.
I like the idea (because it feels Pascalish) to make a code section that checks requirements but the exit condition is up for debate. I personally wouldn’t use the feature if it meant I need to start the tedious process of wrapping everything in try blocks and taking on what performance costs there are to exceptions (we can’t opt into exceptions via modeswitch so I don’t know what those things are doing and where they are).
We have custom error systems in our code also so forcing everyone into exceptions would not be nice. I could imagine a bail condition that was jumped to but it would have to be in the code section. That’s usually how we do it now anyways so it shouldn’t be too strange.
function MakeHero (name: string; hp: integer; level: integer): THero;
name <> ‘’;
hp > 0;
(level > 0) and (level < 10);
MyCustomErrorHandler(‘MakeHero() params are invalid’);
More information about the fpc-pascal