Do pure functions solve the "return const" problems?
Janice Caron
caron800 at googlemail.com
Wed Apr 2 12:21:33 PDT 2008
On 02/04/2008, Yigal Chripun <yigal100 at gmail.com> wrote:
> 1) since the purpose of pure functions as I understand it is thread-safe
> functions,
It isn't. A pure function is a function with no side effects.
> than why should we care if they have side affects
See above. Knowing that a function f is pure allows the compiler to
make optimisations it cannot make with non-pure functions. For
example:
x = f() + f();
can be optimised to
x = 2 * f();
thereby eliminating one entire function call. This makes your code go faster.
Pure functions also happen to be thread-safe, but not all thread-safe
functions are pure.
More information about the Digitalmars-d
mailing list