D const design rationale
Reiner Pope
some at address.com
Sat Jun 23 02:40:20 PDT 2007
Walter Bright wrote:
>
>> I can appreciate that 'invariant' may be of tremendous use to the
>> compiler, but I balk at the notion of adding language features that
>> seem largely intended as compiler "hints."
>
> It's a lot more than that. First, there's the self-documenting aspect of
> it. Second, it opens the way for functional programming, which can be of
> huge importance.
>
You mention functional programming a fair bit with respect to const,
which is nice to hear. But nothing in the current const system allows
you to declare a verifiably 'pure' function; can we expect some
annotation for functions which says 'this function doesn't read/write
any global variables?'
int b
int foo()
{
b++;
return b * 2;
}
pure int square(int x)
{
return x * x;
}
pure int baz()
{
return foo(); // fails: foo is not pure
}
More information about the Digitalmars-d
mailing list