<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">2016-07-28 16:37 GMT+02:00 Michael Van Canneyt <span dir="ltr"><<a href="mailto:michael@freepascal.org" target="_blank">michael@freepascal.org</a>></span>:<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">Are there additional benefits I have missed ?<span class="gmail-"><br>
<br></span></blockquote><div><br></div><div>Using nilable (I think nilable is better than nullable) records is terrible without default field:</div><div><br></div><div>=== code begin ===</div><div><br></div><div>var</div><div> n: TNilable<TRec>;</div><div> x: TRec;</div><div>begin</div><div> { </div><div> </div><div> ... let say that n is assigned somewhere, assume that n.HasValue = true</div><div> </div><div> }</div><div> // to change any field in nilable n you need to...</div><div> x := n.Value;</div><div> x.foo1 := 10;</div><div> x.foo2 := 'abc';</div><div> n := x;</div><div>end.</div><div><div><br></div><div>=== code end ===</div></div><div><br></div><div>instead of:</div><div><br></div><div><div>=== code begin ===</div><div><br></div><div>var</div><div> n: TNilable<TRec>;</div><div>begin<br></div><div> { </div><div> </div><div> ... let say that n is assigned somewhere, assume that n.HasValue = true</div><div> </div><div> }</div><div> x.foo1 := 10;<br></div><div> x.foo2 := 'abc';</div><div>end.<br></div><div><div><br></div><div>=== code end ===</div></div><div> <br></div></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">I can live with the 'ascetic' version :-)<br>
<br>
Since the following:<br>
<br>
Procedure SomeTest(Var X : Integer);<br>
<br>
begin<br>
X:=1; end;<br>
<br>
Var<br>
A : TNullable<Integer>;<br>
<br>
begin<br>
SomeTest(A^);<br>
end.<br>
<br>
Will lead to a crash on a null value, I don't think this is a very good idea to add.<br>
We should protect users from crashes, not expose them to it :-)<br></blockquote><div><br></div><div>that will change nothing, just look below. Just harder to usage pure non-pascalish clone of C# struct (finally C# has pointers as nonstandard/unsafe type so feature with direct dereference is disabled by design). </div><div><br></div><div>=== code begin ===<br></div><div><br></div><div>procedure SomeTest(x : Integer);<br>begin<br>end;<br><br>Var<br> A : TNullable<Integer>;<br>begin<br> SomeTest(A.Value); // AV error here!<br>end.<br></div><div><br></div><div>=== code end ====<br></div><div><br></div><div>A^ is shortcut for A.Value but has advantage = direct dereference to Instance.</div><div><br></div></div>-- <br><div class="gmail_signature"><div dir="ltr"><div>Best regards,<br>Maciej Izak</div></div></div>
</div></div>