Thinking about the difference between fixed and 'dynamic' arrays.
Paul Backus
snarwin at gmail.com
Wed Nov 30 02:29:03 UTC 2022
On Tuesday, 29 November 2022 at 18:59:46 UTC, DLearner wrote:
> To me, it appears that there are really two (_entirely
> separate_) concepts:
>
> A. Supporting the useful concept of variable length (but
> otherwise entirely conventional) arrays;
> B. Supporting a language feature that acts as a window to an
> array, through which that array can be manipulated.
>
> And currently these two concepts are combined.
Yes, this is correct.
> Suggestion: it would be clearer if the two concepts were
> separated:
> 1. Convert 'int[] VarArr;' so it produces a straightforward
> _value-type_ variable array, called 'VarArr';
> 2. Implement a new concept 'int slice Window;' to produce an
> object of type 'int slice', called 'Window'.
> 'Window' is a 'slice' into an int array, not an array itself
> or even a variable.
>
> Opinions?
IMO you have it the wrong way around. The built in `T[]` type
should remain the way it is and be used if you want a slice
(i.e., a "window"). If you want a dynamic array with value
semantics, you should use a library-defined container type (e.g.,
`struct DynamicArray`).
Also, to avoid confusion, we should probably go through the
language spec and documentation and change it to say "slice"
instead of "dynamic array" whenever it refers to a `T[]`.
More information about the Digitalmars-d-learn
mailing list