<div dir="ltr">On Mon, Feb 6, 2012 at 21:58, Sven Barth <span dir="ltr"><<a href="mailto:pascaldragon@googlemail.com">pascaldragon@googlemail.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="HOEnZb"><div class="h5">On 06.02.2012 19:51, ik wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hello,<br>
<br>
Let's say I have a function that some of it's code (or all) can be used<br>
in more then one location inside the function itself.<br>
I can make a nested function with the code and set it to inline, make it<br>
normal, or make a recursion with it.<br>
<br>
What's the best practice in your opinion to take, and why ?<br>
</blockquote>
<br></div></div>
Recursion won't help you here, because recursion is something like the following:<br>
<br>
function factorial(aValue: LongInt): LongInt;<br>
begin<br>
if aValue <= 1 then<br>
Result := 1<br>
else<br>
Result := factorial(aValue - 1) * aValue;<br>
end;<br>
<br>
Whether you inline the function or not depends on whether it's a complex function or not. Something like<br>
<br>
function foo(aValue: LongInt): LongInt;<br>
begin<br>
Result := aValue * 6 + 5 - SomeParam;<br>
end;<br>
<br>
can definitely be declared inline. You just need to keep in mind that when inlining a function the function call will be replaced by the function's/procedure's body so the code size will increase (no, you don't need to pay attention for duplicate variable names).<br>
</blockquote><div><br>Thanks Sven, then I think I'll work with the nested function as a "normal" function rather then inline or recursive one.<br> </div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
Regards,<br>
Sven<div class="HOEnZb"><div class="h5"><br></div></div></blockquote><div><br>Ido<br> </div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="HOEnZb">
<div class="h5">
______________________________<u></u>_________________<br>
fpc-pascal maillist - <a href="mailto:fpc-pascal@lists.freepascal.org" target="_blank">fpc-pascal@lists.freepascal.<u></u>org</a><br>
<a href="http://lists.freepascal.org/mailman/listinfo/fpc-pascal" target="_blank">http://lists.freepascal.org/<u></u>mailman/listinfo/fpc-pascal</a><br>
</div></div></blockquote></div><br></div>