July 27, 2014
On Sunday, 27 July 2014 at 08:49:43 UTC, Jonathan M Davis wrote:
> As defined by the language, T[] is a dynamic array. As great as the article is, it was wrong in its use of the terminology, and that's what's caused a lot of the confusion and resulted in arguments over the difference between a dynamic array and a slice (there really isn't any). IIRC, both Walter and Andrei stated in that discussion that T[] is a dynamic array as far as D is concerned and that's not going to change. The article really should be updated to reflect the correct terminology. As far as D is concerned a slice and a dynamic array are the same thing when it comes to arrays. They're just different names for T[], and trying to treat them as different just causes confusion.

Conflating both concepts with the same name is why the article was so dearly needed in the first place.
July 27, 2014
On Sunday, 27 July 2014 at 09:10:26 UTC, Jakob Ovrum wrote:
> On Sunday, 27 July 2014 at 08:49:43 UTC, Jonathan M Davis wrote:
>> As defined by the language, T[] is a dynamic array. As great as the article is, it was wrong in its use of the terminology, and that's what's caused a lot of the confusion and resulted in arguments over the difference between a dynamic array and a slice (there really isn't any). IIRC, both Walter and Andrei stated in that discussion that T[] is a dynamic array as far as D is concerned and that's not going to change. The article really should be updated to reflect the correct terminology. As far as D is concerned a slice and a dynamic array are the same thing when it comes to arrays. They're just different names for T[], and trying to treat them as different just causes confusion.
>
> Conflating both concepts with the same name is why the article was so dearly needed in the first place.

Except that no concepts are being conflated. T[] is the dynamic array. There's a block of memory managed by the GC underneath, but it's completely hidden from the programmer. It is _not_ the dynamic array. It's just a block of memory managed by the GC which is used to manage the memory for dynamic arrays, and it has a completely different type from T[]. It's not even an array in the D sense. The block of memory is referred to by a pointer, not a D array.

It's talk of "which array" owns the memory and the like which causes confusion, and talking about the GC-managed block of memory as being the dynamic array and the T[] that the programmer sees as being the slice is just plain wrong. The T[] is both a slice and a dynamic array (because they're the same thing), whereas the block of memory is neither. I think that the fact that the article tried to call the underlying block of memory a dynamic array has caused a lot of unnecessary confusion.

- Jonathan M Davis
July 27, 2014
>> Conflating both concepts with the same name is why the article was so dearly needed in the first place.
>
> Except that no concepts are being conflated.

Yes, they are. Consider again the sentence I quoted: "Slicing an array means to specify a subarray of it." The word "it" is wrong; for it to be correct, it needs to refer to the underlying memory block, not the "array".

This was the original cause of my confusion, I believe - it led me to think that "T[] is a dynamic array" (by which I mean a concept I understand well from other languages) but in fact, D has redefined the term "dynamic array" to mean something quite different. So, not only is "T[]" NOT the concept I thought it was, what it IS apparently goes by the same name as the concept I had confused it with! For the sake of increased adoption of D, I beg you to reconsider. I am not exaggerating - for a while there I thought I was looking at a huge red flag, and if I didn't already appreciate other strengths of D, I would have stopped there.
July 27, 2014
On Sunday, 27 July 2014 at 12:03:05 UTC, Jonathan M Davis wrote:
> Except that no concepts are being conflated. T[] is the dynamic array. There's a block of memory managed by the GC underneath, but it's completely hidden from the programmer. It is _not_ the dynamic array. It's just a block of memory managed by the GC which is used to manage the memory for dynamic arrays, and it has a completely different type from T[]. It's not even an array in the D sense. The block of memory is referred to by a pointer, not a D array.
>
> It's talk of "which array" owns the memory and the like which causes confusion, and talking about the GC-managed block of memory as being the dynamic array and the T[] that the programmer sees as being the slice is just plain wrong. The T[] is both a slice and a dynamic array (because they're the same thing), whereas the block of memory is neither. I think that the fact that the article tried to call the underlying block of memory a dynamic array has caused a lot of unnecessary confusion.
>
> - Jonathan M Davis

This very thread is a testament to the fact that no, it's not completely hidden, and it is the conflation that causes confusion, and clarity only comes when the two concepts are explained separately.

This matches my experience when I teach about D's arrays on IRC too - people generally feel enlightened after reading the array article.

It's debatable whether hamfisting dynamic array capabilities onto a simple slice type was a good idea or not (T[new], anyone?), but we should be as clear with the current situation as possible. Pretending there isn't a problem is ignoring the cries of D newbies everywhere. Please stop.

July 27, 2014
On Sunday, 27 July 2014 at 13:03:13 UTC, Jakob Ovrum wrote:
> On Sunday, 27 July 2014 at 12:03:05 UTC, Jonathan M Davis wrote:
>> Except that no concepts are being conflated. T[] is the dynamic array. There's a block of memory managed by the GC underneath, but it's completely hidden from the programmer. It is _not_ the dynamic array. It's just a block of memory managed by the GC which is used to manage the memory for dynamic arrays, and it has a completely different type from T[]. It's not even an array in the D sense. The block of memory is referred to by a pointer, not a D array.
>>
>> It's talk of "which array" owns the memory and the like which causes confusion, and talking about the GC-managed block of memory as being the dynamic array and the T[] that the programmer sees as being the slice is just plain wrong. The T[] is both a slice and a dynamic array (because they're the same thing), whereas the block of memory is neither. I think that the fact that the article tried to call the underlying block of memory a dynamic array has caused a lot of unnecessary confusion.
>>
>> - Jonathan M Davis
>
> This very thread is a testament to the fact that no, it's not completely hidden, and it is the conflation that causes confusion, and clarity only comes when the two concepts are explained separately.
>
> This matches my experience when I teach about D's arrays on IRC too - people generally feel enlightened after reading the array article.
>
> It's debatable whether hamfisting dynamic array capabilities onto a simple slice type was a good idea or not (T[new], anyone?), but we should be as clear with the current situation as possible. Pretending there isn't a problem is ignoring the cries of D newbies everywhere. Please stop.

The array article does a great job explaining a lot about D arrays, and it definitely has helped people understand them. But it uses the wrong terminology, and that's my point. In D, T[] is a dynamic array and a slice. As far as D is concerned, there is no difference. T[] normally refers to a block of memory that the GC manages, but that block of memory is not typed as a dynamic array. And that's where the article gets it wrong.

- Jonathan M Davis
July 27, 2014
On Sunday, 27 July 2014 at 08:23:05 UTC, Marc Schütz wrote:
> Sure, it could be used as a lightweight bugtracker. But them, someone would have to watch the comments, and actually turn them into PRs, and remove the comments when the PRs are merged.

I also find example code useful sometimes when a function/feature is under-documented or just plain buggy.

If people added the examples they provide in the forums to the doc pages then it would be easier to learn the language?

If people added links to stackoverflow/articles when they find them, and put it in the correct section, then it would be easier to dig deeper into the knowledge base?


You could have a "sign of authority" on usernames that are official "D experts" and let them "approve" correct comments. When you have received N approvals you can win a D T-shirt? :)


A lot of noise is a sign of a documentation page that needs work or that the page need to be broken up into several pages.
July 27, 2014
> The array article does a great job explaining a lot about D arrays, and it definitely has helped people understand them. But it uses the wrong terminology, and that's my point. In D, T[] is a dynamic array and a slice. As far as D is concerned, there is no difference. T[] normally refers to a block of memory that the GC manages, but that block of memory is not typed as a dynamic array. And that's where the article gets it wrong.

Look:

auto c = new MyClass();

The D spec calls c "a reference to a class instance".

This is good terminology because there can be a many-to-one relationship between references and classes. In contrast, early writing on Java or C# (I forget which) used to call c "an object". This was a misguided attempt to hide the fact that there's a reference involved - a fact that cannot and should not be hidden. And the thing it refers to needs a name more specific than "a block of memory".


Now:

int[] i = new int[5];

For now let's call 'i' a "dynamic array" and the thing it refers to
a "foobar". The point is still the same: As with object references,
there can be a many-to-one relationship between "dynamic arrays" and "foobars", and attempts to hide that relationship (e.g. by not giving "foobar" a name more specific than "block of memory") are misguided.

Furthermore, the concept we're calling a "foobar" here is usually called a "dynamic array" in other languages. So IMO D is making the same mistake as when people call c above "an object".
July 28, 2014
On Sunday, 27 July 2014 at 18:52:55 UTC, Andrew Godfrey wrote:
> Now:
>
> int[] i = new int[5];
>
> For now let's call 'i' a "dynamic array" and the thing it refers to
> a "foobar".

'i' is a "dynamic array" and contains a reference to a "block of memory."

Frankly I don't see how making the distinction at 'dynamic array' and 'slice' will help with the particular confusion. For example, in Go a slice stomps memory:

http://he-the-great.livejournal.com/48672.html
July 28, 2014
On 07/27/2014 01:49 AM, Jonathan M Davis wrote:

> As defined by the language, T[] is a dynamic array.

I bet that terminology is from before the design of slices was finalized about four years ago.

> difference between a dynamic array and a slice (there really isn't any).

At the risk of beating this never-dying horse, when you say that, I don't think you can explain the following code:

    int[] a = [ 1, 2, 3 ];
    int[] b = a;

According to your terminology, 'a' is a dynamic array and 'b' is another dynamic array. Knowing how good you know D, I can't understand how you think that way. In fact, both 'a' and 'b' are slices into the single dynamic array. The dynamic array is managed by the GC. So, there are three entities in that code: One dynamic array and two slices.

> IIRC, both Walter and Andrei stated in that discussion that T[]
> is a dynamic array as far as D is concerned and that's not
> going to change.

I would like to hear Andrei's and Walter's current opinions on the matter.

> The article really should be updated to reflect the correct
> terminology.

It should stay as is to maintain sanity. :)

> As far as D is concerned a slice and a dynamic array are the
> same thing when it comes to arrays. They're just different
> names for T[], and trying to treat them as different just
> causes confusion.

To me, treating them differently removes all the confusion.

> - Jonathan M Davis

Ali

July 29, 2014
On Monday, 28 July 2014 at 22:29:04 UTC, Ali Çehreli wrote:
> On 07/27/2014 01:49 AM, Jonathan M Davis wrote:
> > difference between a dynamic array and a slice (there really
> isn't any).
>
> At the risk of beating this never-dying horse, when you say that, I don't think you can explain the following code:
>
>     int[] a = [ 1, 2, 3 ];
>     int[] b = a;
>
> According to your terminology, 'a' is a dynamic array and 'b' is another dynamic array. Knowing how good you know D, I can't understand how you think that way. In fact, both 'a' and 'b' are slices into the single dynamic array. The dynamic array is managed by the GC. So, there are three entities in that code: One dynamic array and two slices.

It's simple, D's dynamic arrays _never_ own their memory. It's owned by the GC, or it's a slice of a static array, or it points to a buffer that was malloc-ed, etc. The type T[] says _nothing_ about who or what owns the memory or what backs the array. Understanding how it works when they're generated by the GC is very helpful in determining when a dynamic array / slice is likely to be reallocated, but it's pretty irrelevant to the type itself.

In your example, both a and b are dynamic arrays which are slices of the same underlying block of memory. It's a and b which are the dynamic arrays, not the buffer. From the type system's perspective, this would be the same

int[3] z = [1, 2, 3];
int[] a = z;
int[] b = a;

a and by are still exactly the same type - dynamic arrays - and they will behave exactly the same save for the fact that due to the fact that they're now backed by a static array rather than the GC, their capacity is guaranteed to be 0, and it's unsafe for them to escape from the scope of z.

The underlying buffer for a GC-backed dynamic array isn't even a D array. It's a druntime-specific data structure which holds a buffer via pointer.

The array article does a great job of explaining a lot of the details about how D arrays work (especially those backed by the GC), but it got the terminology wrong, and I definitely think that it should be fixed.

- Jonathan M Davis