May 30, 2013
On Thu, 30 May 2013 12:46:39 -0400, Maxim Fomin <maxim@maxim-fomin.ru> wrote:

> Please provide reasons why it is wrong (but without explanation how druntime allocates memory which is irrelevant).

It's wrong in that D's spec re-defines dynamic arrays from the traditional definition (I think for the sake of simplicity, but I didn't write the definition, so I'm not sure).  D's slices aren't dynamic arrays, no matter how many specs say so.

> That's nice to hear, but at that point there would be no point for discussions. I see no roots from where contradictory definition in article comes from.

It comes from the experience of observing anyone who knows what a dynamic array is, comes to D, sees from the spec that it's T[], and then gets confused when T[] does not act like the dynamic array they know from C++, Java, C#, etc.

In other words, explaining countless times on the newsgroups how slices work prompted me to write the article.  It's not an easy concept to grasp.

-Steve
May 30, 2013
On Thu, 30 May 2013 12:56:46 -0400, Steven Schveighoffer <schveiguy@yahoo.com> wrote:

> On Thu, 30 May 2013 12:46:39 -0400, Maxim Fomin <maxim@maxim-fomin.ru> wrote:
>
>> Please provide reasons why it is wrong (but without explanation how druntime allocates memory which is irrelevant).
>
> It's wrong in that D's spec re-defines dynamic arrays from the traditional definition (I think for the sake of simplicity, but I didn't write the definition, so I'm not sure).  D's slices aren't dynamic arrays, no matter how many specs say so.

Oh, you were looking for an actual *functional* differences between slices and dynamic arrays.

The major concept difference is ownership.  Two references to the same array do not mysteriously split when length is extended on one of those references.  All references to the same array always refer to the same array, even when it has to reallocate to extend length.  Slices differ from this behavior, and I can say with great confidence that this is the most confusing aspect of D slices.

In addition, shrinking a dynamic array invalidates any data that has now been removed.  D slices do not do this either.  Because slices simply point at data, they don't own it.

-Steve
May 30, 2013
On 05/30/2013 10:09 AM, Steven Schveighoffer wrote:

> The major concept difference is ownership.  Two references to the same
> array do not mysteriously split when length is extended on one of those
> references.  All references to the same array always refer to the same
> array, even when it has to reallocate to extend length.  Slices differ
> from this behavior, and I can say with great confidence that this is the
> most confusing aspect of D slices.
>
> In addition, shrinking a dynamic array invalidates any data that has now
> been removed.  D slices do not do this either.  Because slices simply
> point at data, they don't own it.

I tried to name those semantics by "discretionary sharing semantics":

  http://forum.dlang.org/thread/hd2fot$mkc$1@digitalmars.com

I have not read that old post mine again now but I still like the term. :)

Ali

May 30, 2013
On 05/30/2013 09:23 AM, Maxim Fomin wrote:

> Note, that there is no problem with alising of slice and dynamic
> array, but there is problem with denying that dynamic array (according
> to spec) is a slice.

That gets back to your "banana" example. Slice and dynamic array is the same thing only because the spec says so. They do not have the same semantics of dynamic arrays as I know in programming.

They are not dynamic in the sense that they are on the heap. (Both your and my examples have trivially shown that.)

Further, they are not arrays in the sense that they own elements.

Therefore, calling this concept "dynamic array" is a historical accident. The spec may call it "dynamic array" but the spec cannot change what "dynamic array" means.

Ali

May 30, 2013
On Thu, 30 May 2013 13:33:31 -0400, Ali Çehreli <acehreli@yahoo.com> wrote:

> They are not dynamic in the sense that they are on the heap. (Both your and my examples have trivially shown that.)

Dynamic arrays themselves do not have to be allocated on the heap.

A C++ std::vector is a valid dynamic array type, yet it's actual container can exist on the stack.  The data is on the heap, but where the data is located is irrelevant.  The important thing here is that any reference to the same instance always affects that instance.  It doesn't mysteriously split off into another instance.

-Steve
May 30, 2013
On Thursday, 30 May 2013 at 17:09:05 UTC, Steven Schveighoffer wrote:
> On Thu, 30 May 2013 12:56:46 -0400, Steven Schveighoffer <schveiguy@yahoo.com> wrote:
>
>> On Thu, 30 May 2013 12:46:39 -0400, Maxim Fomin <maxim@maxim-fomin.ru> wrote:
>>
>>> Please provide reasons why it is wrong (but without explanation how druntime allocates memory which is irrelevant).
>>
>> It's wrong in that D's spec re-defines dynamic arrays from the traditional definition (I think for the sake of simplicity, but I didn't write the definition, so I'm not sure).  D's slices aren't dynamic arrays, no matter how many specs say so.
>
> Oh, you were looking for an actual *functional* differences between slices and dynamic arrays.
>
>
> -Steve

I was looking for explanation why after years of stable array definition one article abolish official spec (without changing it) and major implementation without any Walter or Andrei approval. I got an answer in previous comment but found it unsatisfactory: simply because somebody considers that D definitions contradict to some external notions is not a reason to change it. There are other places in D which do not correspond with names in other languages or with general terms. Also, there is as much opinions, as much people, so moving language toward some external definition is a problematic task.

It would be good if Walter or Andrei comment on this.
May 30, 2013
On Thursday, May 30, 2013 12:56:46 Steven Schveighoffer wrote:
> On Thu, 30 May 2013 12:46:39 -0400, Maxim Fomin <maxim@maxim-fomin.ru>
> 
> wrote:
> > Please provide reasons why it is wrong (but without explanation how druntime allocates memory which is irrelevant).
> 
> It's wrong in that D's spec re-defines dynamic arrays from the traditional definition (I think for the sake of simplicity, but I didn't write the definition, so I'm not sure). D's slices aren't dynamic arrays, no matter how many specs say so.

Well, we've clearly ended up with a few terms that get re-used with different meanings and cause confusion. The terms dynamic array and slices are generally used interchangeably by the spec and plenty of D users, whereas you're basically arguing that D doesn't even have dynamic arrays. Rather, dynamic arrays are basically an implementation feature of druntime. However, trying to call them all slices instead of dynamic arrays has its own issues, because slices are for more than just arrays - they're a core concept of ranges, many of which have no relation with arrays. So, I guess that the best term that we have would be array slice (not even dynamic array slice, since it could be a silce of a static array). But even if we agreed that that was the correct term and fixed the spec, it's still ripe for confusion.

It reminds me of the tuple fiasco. Having the bulit-in tuples that TypeTuple wraps called tuples causes all kinds of confusion with std.typecons.Tuple (on top of the fact that the built-in tuples arguably aren't even tuples).

We seem to have at least a couple of serious terminology/naming problems on our hands, and I'm not sure that we have good solutions for any of them. For the moment at least, we're stuck trying to give good explanations in order to clarify the situation.

And of course, with the spec, TDPL, and the standard library (e.g. isDynamicArray) all using the term dynamic array pretty much interchangeably with the term slice when discussing arrays, I don't know that there's any chance of really clarifying the situation beyond explaining it to people.

- Jonathan M Davis
May 30, 2013
On Thursday, May 30, 2013 19:44:17 Maxim Fomin wrote:
> I was looking for explanation why after years of stable array definition one article abolish official spec (without changing it) and major implementation without any Walter or Andrei approval. I got an answer in previous comment but found it unsatisfactory: simply because somebody considers that D definitions contradict to some external notions is not a reason to change it. There are other places in D which do not correspond with names in other languages or with general terms. Also, there is as much opinions, as much people, so moving language toward some external definition is a problematic task.
> 
> It would be good if Walter or Andrei comment on this.

Then you'll probably need to start a new thread on it. They're unlikely to see any of this (let alone comment on it) if they haven't already been involved in the thread, and I don't think that either of them have said anything in this thread.

- Jonathan M Davis
May 30, 2013
On Thursday, 30 May 2013 at 17:33:32 UTC, Ali Çehreli wrote:
> On 05/30/2013 09:23 AM, Maxim Fomin wrote:
>
> > Note, that there is no problem with alising of slice and
> dynamic
> > array, but there is problem with denying that dynamic array
> (according
> > to spec) is a slice.
>
> That gets back to your "banana" example. Slice and dynamic array is the same thing only because the spec says so. They do not have the same semantics of dynamic arrays as I know in programming.
> They are not dynamic in the sense that they are on the heap. (Both your and my examples have trivially shown that.)
> Further, they are not arrays in the sense that they own elements.
> Therefore, calling this concept "dynamic array" is a historical accident. The spec may call it "dynamic array" but the spec cannot change what "dynamic array" means.
>
> Ali

Really it is repetition of banana example. One article severely changes spec because there is opinion that existing spec contradicts some ideas. And now it is claimed that some things are false just because they are false. It is a hijack of language which allows to anyone whose opinion is somewhat different to D to claim that his opinion is what D actually is. Without Walter or Andrei approval such claims are cheap.
May 30, 2013
On Thu, 30 May 2013 13:52:08 -0400, Jonathan M Davis <jmdavisProg@gmx.com> wrote:


> And of course, with the spec, TDPL, and the standard library (e.g.
> isDynamicArray) all using the term dynamic array pretty much interchangeably
> with the term slice when discussing arrays, I don't know that there's any
> chance of really clarifying the situation beyond explaining it to people.

I think clarifying is what we need to do.  We need to inform the user reading the spec that although D calls them dynamic arrays, they aren't true dynamic arrays in the formal sense.

array slices is a better/more appropriate term IMO.  I agree it would be near impossible to change all references to dynamic arrays, especially isDynamicArray.

-Steve