resizeable arrays: T[new]
Bill Baxter
dnewsgroup at billbaxter.com
Mon Jun 4 19:30:42 PDT 2007
Tom S wrote:
> Derek Parnell wrote:
>> On Mon, 04 Jun 2007 10:45:09 -0700, Walter Bright wrote:
>>
>>>>> T[n] a; // static array
>>>>> T[] b; // dynamic array
>>>>> T[new] c; // resizeable array
>>>> I'd propose a different nomenclature:
>>>>
>>>> T[n] a; // static array
>>>> T[] b; // (array) slice
>>>> T[new] c; // dynamic array
>>> I like "resizeable" array because it is pretty clear what it does.
>>
>> I think you are quite wrong Walter. The new interpretation of 'x[]' is
>> almost identical to what we used to think of as a slice. And the
>> interpreatation of 'x[new]' is exactly what used to be known as a dynamic
>> array.
>> Your change will effect all code immediately whereas reversing the
>> (changed) meaning of '[]' and '[new]' to mean 'resizable' and 'slice'
>> will
>> allow coders to change their coding over time. Unless of course that's
>> what
>> you are trying to do ...
>
> Except that the non-resizable arrays will be more common in use than the
> fully dynamic ones. Thus, the resizable are a special case and deserve
> special syntax. *Except* that it's similar to const-by default, while D
> will use mutable-by default.
I think it really depends. I can imagine for a lot of folks it will
basically boil down to parameter vs. local variable. If it's a
parameter you want slice-semantics, if it's a local variable you want
resizeable semantics. A quick grep through my code gave me about 400
lines where I used '~='. That doesn't tell you all that much, but it
does give something close to an upper bound. For each of those lines a
T[] somewhere is going to need to be changed to a T[new] (or whatever).
The number could be less if I'm using auto. But I also use
T[] x; x.length = N;
a lot. Those will need to be changed too.
On the other hand "[]" appears about 1700 times. That says to me that
arrays that I don't resize (whether in paramter or not) are probably
significantly more common than those I do. But either way it's a
significant amount of code to change.
--bb
More information about the Digitalmars-d-announce
mailing list