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/