On Mon, Feb 6, 2012 at 21:58, Sven Barth <pascaldra...@googlemail.com>wrote:
> On 06.02.2012 19:51, ik wrote: > >> Hello, >> >> Let's say I have a function that some of it's code (or all) can be used >> in more then one location inside the function itself. >> I can make a nested function with the code and set it to inline, make it >> normal, or make a recursion with it. >> >> What's the best practice in your opinion to take, and why ? >> > > Recursion won't help you here, because recursion is something like the > following: > > function factorial(aValue: LongInt): LongInt; > begin > if aValue <= 1 then > Result := 1 > else > Result := factorial(aValue - 1) * aValue; > end; > > Whether you inline the function or not depends on whether it's a complex > function or not. Something like > > function foo(aValue: LongInt): LongInt; > begin > Result := aValue * 6 + 5 - SomeParam; > end; > > 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). > ‎Thanks Sven, then I think I'll work with the nested function as a "normal" function rather then inline or recursive one. > > Regards, > Sven > > Ido > ______________________________**_________________ > fpc-pascal maillist - > fpc-pascal@lists.freepascal.**org<fpc-pascal@lists.freepascal.org> > http://lists.freepascal.org/**mailman/listinfo/fpc-pascal<http://lists.freepascal.org/mailman/listinfo/fpc-pascal> >
_______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal