[fpc-devel] Optimizing unused return values of inline functions

Sven Barth pascaldragon at googlemail.com
Mon Aug 21 20:06:25 CEST 2017


On 21.08.2017 13:22, Michael Van Canneyt wrote:
> 
> 
> On Mon, 21 Aug 2017, Benito van der Zander wrote:
> 
>> Hi,
>>
>>> This pattern is not inherently efficient. Why should it be ? 
>>
>>
>> It is not efficient, because of the pointless instruction!
> 
> I am not speaking of the current FPC implementation. It may well be that
> the
> code is not most optimal.
> 
> I am asking, why do you think *this pattern* (of always returning self)
> should be inherently more efficient ?

The pattern definitely has its uses. E.g. in the user space of our
operating system at work we have a StdOutPrinter class that is used like
this:

=== code begin ===

StdIO::stdOutPrinter()->out("Helllo World ")->out(42)->out("
")->hex()->out(42)->line();

=== code end ===

Each function returns again the instance that was returned by
StdIO::stdOutPrinter().

The whole pattern is called method chaining or fluent interface:
- https://en.wikipedia.org/wiki/Method_chaining
- https://en.wikipedia.org/wiki/Fluent_interface

Regards,
Sven



More information about the fpc-devel mailing list