[lug] Bash shell script question

BC bcarr at purgatoire.org
Wed Feb 21 19:40:46 MST 2018



On 2/21/2018 7:20 PM, Zan Lynx wrote:
> On Wed, Feb 21, 2018 at 06:25:14PM -0700, BC wrote:
>> Go's slices are wonderful, aren't they?
> They are pretty great but like a few other Go constructs, they contain
> hidden traps.
>
> You have to always remember that the slice is actually a pointer. If you
> pass a slice into a goroutine you either have to not use it from
> anywhere else, or you have to use a sync.Mutex.

You are waaaaay ahead of me.  I'm nowhere near ready to learn how to 
use go routines and all they entail.  Same with channels.

> You also have to remember that appending to a slice returns a
> potentially, but not always new copy of the backing array. I've seen
> problems where some code kept writing to an old copy of the slice, but
> that wasn't actually the array that was currently in use.

Yes, I'm taking care to not get caught in that trap.  That is why I'm 
starting with an easy project, converting someone else's working 
"program" into Go.

> And there's potential garbage collection issues. It can surprise some
> people that holding a byte slice of six characters can pin a 4K page.
> This can happen a lot when parsing out of a file stream, then storing
> that slice into a data structure without copying.

I grew up in the era when 4k of RAM was a lot.  But now...  A trifling 
in the big scheme of things.

> The same is true of maps. Maps all hold internal pointers and need to be
> single-threaded or guarded by Mutex.

I haven't learned about maps, yet.

> Still, Go has way fewer problems than C or C++. I do like it.

Oh yeah.  I've drunk the Koolaid.  Never could stomach learning C 
(never tried C++), but Go is quite welcoming in the way it works.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lug.boulder.co.us/pipermail/lug/attachments/20180221/1b6bde91/attachment.html>


More information about the LUG mailing list