<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<div class="moz-cite-prefix">On 13/04/2019 18:40, Benito van der
Zander wrote:<br>
</div>
<blockquote type="cite"
cite="mid:8430a73f-d071-283f-65d3-8e390fc4d301@benibela.de">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<div id="smartTemplate4-template">Hi,<br>
</div>
<div><br>
</div>
<div>the parameter is already optional without any modifier, since
you can always pass nil for it.</div>
<div><br>
</div>
<div>Perhaps there could be the opposite modifier, so the function
cannot be called with nil. Like<br>
</div>
<div>
<pre class="moz-quote-pre" wrap="">procedure DoThis(nonnil var obj: TObject); </pre>
<p>and then you need to check if it is nil, before calling
DoThis .<br>
</p>
</div>
<div><br>
</div>
<div>Or you put it in the type. type TSomeObject = nonnil
class(TObject)... and then it would never be allowed to be nil.
<br>
Or for pointers type PDude = nonnil ^TDude; <br>
If you would want to use such a nonnil class as field in another
class, you would need to initialize it in the constructor.<br>
</div>
<br>
</blockquote>
<br>
Well nil is only with objects. For strings you could expect that
there are not empty. <br>
For integers you can have sub-ranges. But for float, you may have a
condition that says > 0.<br>
<br>
I think this goes towards
<a class="moz-txt-link-freetext" href="https://en.wikipedia.org/wiki/Design_by_contract">https://en.wikipedia.org/wiki/Design_by_contract</a> <br>
pre/post conditions.<br>
<br>
Those can then be applied for anything. And the compiler can add
compile/runtime checks, the same way it does range checking.<br>
<br>
As stated on wikipaedia this also plays towards docs. If a function
has a postcondition that either forbids nil, or explicitly allows
it, then you do not need to look at its code. You know what to
expect.<br>
<br>
</body>
</html>