[Article Contest, first draft] D Slices

David Gileadi gileadis at NSPMgmail.com
Wed May 18 11:44:33 PDT 2011


On 5/18/11 11:03 AM, Steven Schveighoffer wrote:
> Please, if you have any comments or recommendations, let me know.

First off, this is a fantastic article.  Thanks for clearly explaining a 
fairly subtle concept.  I'm especially happy to finally understand how 
appending to a slice can avoid reallocating and what assumeSafeAppend does.

I do have a couple of nits:

1. After the shrinkTo2 example, you say "This might look like you 
changed the passed arr's length to 2, but it actually did not affect 
anything," followed by the reason.  It took me a bit to realize why this 
was so.  I think it would be clearer if the example included the call to 
shrinkTo2, e.g.

void shrinkTo2(int[] arr)
{
     if(arr.length > 2)
         arr.length = 2;
}

int[] a = new int[5];
shrinkTo2(a);

And then you pointed out that a's length hasn't changed after the call. 
  Including the calling code might also be helpful for the Determinism 
example, for the same reason.

2. In the section "A Slice You Can Append On" the phrase "The slice does 
not own it's data" should remove the apostrophe from "its".  There is at 
least one other place in the document that also make this mistake, under 
the Caching section.

Again, fantastic article.

-Dave


More information about the Digitalmars-d mailing list