resizeable arrays: T[new]

Tom S h3r3tic at remove.mat.uni.torun.pl
Mon Jun 4 17:12:13 PDT 2007


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.

Long story short, IMHO, it makes more sense to do const-by-default 
everywhere, just as using non-resizable arrays by default. But what 
you're suggesting will probably be more consistent with the planned 
constness facilities. And as I understand it, their main selling point 
over const-by-default is the smaller number of changes required in 
existing code.


-- 
Tomasz Stachowiak
http://h3.team0xf.com/
h3/h3r3tic on #D freenode



More information about the Digitalmars-d-announce mailing list