const sucks
Bill Baxter
wbaxter at gmail.com
Sat Oct 18 14:52:29 PDT 2008
On Sun, Oct 19, 2008 at 6:35 AM, Andrei Alexandrescu
<SeeWebsiteForEmail at erdani.org> wrote:
> John Reimer wrote:
>>
>> Are there any other drawbacks with default immutability other than
>> breaking with the norm?
>
> Well for one thing much of OO style involves creating few objects that hold
> their state and evolve in well-defined ways. Many objects are
> "entity" objects, meaning that holding a reference to a particular object is
> the way to stay in touch. In FP style new objects are being created all the
> time, so the programming styles are very different.
>
> But by and large I find it very interesting that the tide has changed to the
> extent that this option is being discussed. It's good progress from the
> const-should-die-a-gruesome-death view :o).
I think you mean "this option is being discussed *once again*". It
was discussed quite a lot before the current invariant/const was
implemented. The consensus was definitely that it was worth a shot.
But it did not get a shot.
I recall Walter's main argument against it was that local variable
really shouldn't be const-by-default since you're usually creating
them because you want to manipulate them. But then you end up with a
system where local variable declarations and parameter declarations
follow very different rules. "int[] foo" in one place means something
different from "int[] foo" in the other place. I'm not convinced this
would be that confusing, though. There could be other problems with
const-by-default in parameters, but that one doesn't seem like such a
big deal.
--bb
More information about the Digitalmars-d
mailing list