Slices and Dynamic Arrays
Tony
tonytdominguez at aol.com
Sun Dec 31 01:57:58 UTC 2017
On Friday, 29 December 2017 at 23:13:20 UTC, Jonathan M Davis
wrote:
> The term "slice" is a bit overused in D, meaning a variety of
> things. It doesn't help that some folks dislike the official
> terminology. In general, a slice is a contiguous group of
> elements. A slice of memory would be a contiguous block of
> memory. A dynamic array therefore refers to a slice of memory
> and could be called a slice, but it's also the case that using
> the slice operater on a container is called slicing - e.g.
> rbt[] would give you a range over the container rbt, and that
> range is a slice of the container, but it's not an array at all.
>
For me, it is confusing to use "slice" and "dynamic array" as
synonyms. My initial impression was that they must have different
code underlying them, and different behavior. I would pick one or
the other. It should be:
D Arrays
- Static
- Dynamic
or
D Arrays
- Static
- Slice
The DLang Tour has a section on Slices that says in bold "Slices
and dynamic arrays are the same". I think that sentence deserves
an explanation as to why there are two terms being utilized for
the same thing. I would prefer that "slice" as a noun was used
only for the time when a dynamic array was initialized from a
slice of another array. Or better yet - slice was never used as a
noun - only a verb or adjective: took a slice of array A to form
a slice dynamic array B (or slice-intialized dynamic array B).
D Arrays
- Static
- Dynamic
- Slice-Initialized Dynamic
More information about the Digitalmars-d-learn
mailing list