NB I’m unable to reproduce this bug without the pointer indirection.

On Tuesday, September 4, 2018 at 3:38:35 AM UTC+10, Sam Whited wrote:
>
> On Mon, Sep 3, 2018, at 04:10, ama...@naucera.net <javascript:> wrote: 
> > type S []int 
> > 
> > func (s *S) Last() int { 
> >     return (*s)[len(*s) - 1] 
> > } 
>
> On an unrelated matter, the extra indirection is (probably) not what you 
> want here, slices are already a pointer type. For more information see 
> https://blog.golang.org/go-slices-usage-and-internals. 
>
> That is to say, the following works in more or less the same way (and is 
> much easier to read): 
>
> func (s S) Last() int { 
>         return s[len(s)-1] 
> } 
>
> Apologies if this is something you're already aware of; for future 
> generations finding this thread I wanted to mention it. 
>
> —Sam 
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to