[fpc-pascal] Optional param modifier

Martin Frb lazarus at mfriebe.de
Sat Apr 13 23:39:30 CEST 2019


On 13/04/2019 23:17, Ryan Joseph wrote:
> If there was any other way the compiler could make this contract more 
> concrete and reliable then comments I’d be happy to hear it.

I don't know what others think of it, but
https://en.wikipedia.org/wiki/Design_by_contract
look at pre/post-conditions.

It basically is like assertions. But it is a bit more, because there are 
rules for inheritance. So it should be part of the declaration, not the 
implementation.

Once such conditions exists, the compiler could be enhanced in different 
ways:
- insert the correct assertions
- check at compile time, if possible (may give errors, warnings, hints, 
depending how certain the compiler is)

Of course it does a bit of the opposite of what you did. It allows to 
say, when a param is not allowed nil.

By implication any param that has no pre-condition is allowed nil, and 
the compiler should assume it may be nil.

----------
Back to your original issue.

To express that a param could be nil, to indicate it is omitted. If you 
can put it to the end of the list
   procedure Foo(Bar: TBar; Opt: TOpt = nil);
makes it perfectly clear, that nil is an intended accepted value



More information about the fpc-pascal mailing list