pure functions/methods

Namespace rswhite4 at googlemail.com
Fri Apr 20 03:42:57 PDT 2012


On Friday, 20 April 2012 at 09:55:28 UTC, Timon Gehr wrote:
> On 04/20/2012 10:06 AM, Namespace wrote:
>> The sense of pure functions isn't clear to me.
>> What is the advantage of pure functions / methods?
>
> 1. It enables stateless reasoning about program parts.
> 2. It enables certain compiler optimizations.
>
>> I inform the compiler with "const" that this method does not 
>> change the
>> current object, and therefore he can optimize (at least in 
>> C++) this
>> method.
>
> const on a method does not give any guarantees in C++. A C++ 
> compiler cannot perform optimizations based on a const method.
>
>> How and what optimized the compiler if i have "pure" or "const
>> pure" functions / methods?
>
> DMD does not do a lot there currently.
>
> This article seems to discuss what GCC does with pure functions:
> http://lwn.net/Articles/285332/

So only GDC optimized "pure" functions at all?


More information about the Digitalmars-d-learn mailing list