<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Aug 22, 2017 at 1:15 PM, Michael Van Canneyt <span dir="ltr"><<a href="mailto:michael@freepascal.org" target="_blank">michael@freepascal.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="gmail-"><br>
<br>
On Tue, 22 Aug 2017, Thaddy de Koning wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
On <a href="tel:21.08.2017%2013" value="+12108201713" target="_blank">21.08.2017 13</a>:22, Michael Van Canneyt wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
<br>
On Mon, 21 Aug 2017, Benito van der Zander wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Hi,<br>
<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
This pattern is not inherently efficient. Why should it be ?<br>
</blockquote>
<br>
<br>
It is not efficient, because of the pointless instruction!<br>
</blockquote>
<br>
I am not speaking of the current FPC implementation. It may well be that<br>
the<br>
code is not most optimal.<br>
<br>
I am asking, why do you think *this pattern* (of always returning self)<br>
should be inherently more efficient ?<br>
</blockquote>
<br>
The pattern definitely has its uses. E.g. in the user space of our<br>
operating system at work we have a StdOutPrinter class that is used like<br>
this:<br>
<br>
=== code begin ===<br>
<br>
StdIO::stdOutPrinter()->out("H<wbr>elllo World ")->out(42)->out("<br>
")->hex()->out(42)->line();<br>
</blockquote></blockquote>
<br></span>
Call me old-fashioned, but I much prefer<br>
<br>
With StdIO::stdOutPrinter() do<br>
begin<br>
out("Helllo World ");<br>
out(42);<br>
out("");<br>
hex();<br>
out(42);<br>
line();<br>
end;<br></blockquote><div><br></div><div>This works well, but you can't tell the meaning of any single line, unless you're sure that all the methods are indeed defined in stdOutPrinter.</div><div>Imagine</div><div><br></div><div>With StdIO::stdOutPrinter() do<br> begin<br></div> out("Helllo World ");<br> out(size());<br><div> ...</div><div> end;</div><div><br></div><div>with size() belonging to the enclosing class. Someone adds size() to stdOutPrinter and you're toasted.</div><div><br></div><div>I've even seen a nested WITH misuse like</div><div><br></div><div>with src do begin</div><div> with dst do begin</div><div> name := firstName + ' ' + lastName;</div><div> amount := ownAmount;</div><div> ...</div><div> end;</div><div>end;</div><div><br></div><div>which is a terrible and error-prone misuse.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
I see no point or gain in the "fluent" code.</blockquote><div><br></div><div>- It's as compact as WITH, but it's explicit.</div><div>- It can be written in a single line without violating convention.</div><div><br></div></div><br></div></div>