On 4/30/2014 11:57 PM, bearophile wrote:
I agree the people are reluctant to add annotations, but I think it's also
depends on the return of investment of the specific annotation. I am annotating
all my code carefully with "pure", but the ROI of all those purity annotations
is not great.
That's why I want to move more towards attribute inference.
And I agree the piling of special cases is a not clean design. It's now simpler
to ask the compiler if a certain assignment to immutable is allowed or not.
Because I can't remember the supported cases.
> So I suggest a more principled and visible approach at the problem of
ownership
> and uniqueness.
The "supported cases" are not random special case hacks. They are based on a
solid principle - if the expression represents a unique reference to an object,
then it is implicitly convertible to immutable or shared.
For example,
new int;
Formerly, that created a pointer to a mutable int object. It could not be
implicitly cast to a pointer to an immutable int. But we know that operator new
returns the only pointer to what it created, so it should be convertible. This
knowledge was simply added to the compiler.
I don't see anything unprincipled about that, or hard to understand, or hackish,
or whatever.