Inability to dup/~ for const arrays of class objects
Peter Williams
pwil3058 at bigpond.net.au
Thu May 30 21:48:47 PDT 2013
On 31/05/13 12:07, Steven Schveighoffer wrote:
> On Thu, 30 May 2013 20:05:59 -0400, Peter Williams
> <pwil3058 at bigpond.net.au> wrote:
>
>> On 30/05/13 16:21, Ali Çehreli wrote:
>>> On 05/29/2013 06:54 PM, Peter Williams wrote:
>>> > I find the mechanism described in the article a little
>>> disconcerting and
>>> > it certainly needs more publicity as it's a bug in waiting for the
>>> > unwary.
>>>
>>> It certainly is disconcerting. Performance have played a big role in the
>>> current semantics of slices.
>>
>> I should have added that it was the non determinism that disconcerted
>> me. It doesn't really affect me personally as a programmer now that I
>> know about it as I can just avoid it. But it blows out of the water
>> any hopes of having "proveably correct" non trivial code.
>
> I think this is an overstatement. It depends heavily on what you are
> doing, and most usages will be correct.
All uses have to be correct if you want "provably correct" otherwise you
just get "mostly correct".
>
> You can achieve deterministic behavior depending on what you are looking
> for. For certain, you can tell without any additional tools that an
> append will not reallocate if the capacity is large enough.
>
That makes programming much easier, doesn't it. I'll just avoid it by
using:
a = a ~ b;
instead of:
a ~= b;
where I think it might be an issue or is that broken too?
I toy in my mind with the idea that the difference between dynamic
arrays and slices should be that slices are read only and if you write
to them they get reallocated and promoted to dynamic array (kind of like
copy on write with hard linked files). But I'm sure that would just
create another set of problems. Also I imagine that it's already been
considered and discarded. BTW the slice "notation" could still be used
for assigning to sections of an array.
Peter
More information about the Digitalmars-d
mailing list