pure functions/methods
Timon Gehr
timon.gehr at gmx.ch
Fri Apr 20 02:55:27 PDT 2012
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/
More information about the Digitalmars-d-learn
mailing list