[Article Contest, first draft] D Slices

Steven Schveighoffer schveiguy at yahoo.com
Wed May 18 11:51:26 PDT 2011


On Wed, 18 May 2011 14:44:33 -0400, David Gileadi <gileadis at nspmgmail.com>  
wrote:

> 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.

Thanks!

>
> 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.

OK, thanks, I'll do that.

>
> 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.

Yes, its a problem I have ;)

-Steve


More information about the Digitalmars-d mailing list