From louis.krupp at gmail.com Mon Feb 19 04:51:40 2018 From: louis.krupp at gmail.com (Louis Krupp) Date: Mon, 19 Feb 2018 04:51:40 -0700 Subject: [lug] Fwd: Save 55% During Our Presidents' Day Sale In-Reply-To: <0.1.A2.2BE.1D3A96CA95E896A.0@om-fen.rsys2.com> References: <0.1.A2.2BE.1D3A96CA95E896A.0@om-fen.rsys2.com> Message-ID: FYI... ---------- Forwarded message ---------- From: InformIT Date: Mon, Feb 19, 2018 at 3:30 AM Subject: Save 55% During Our Presidents' Day Sale To: louis.krupp at gmail.com Save 55% when you buy 2 or more books, eBooks, video training, or software through February 23, 2018. Offer includes free U.S. shipping. [image: InformIT] [image: Buy 2, Save 55% in the Presidents' Day Sale from InformIT] For a limited time, *buy 2, save 55%* * off the list price of books, eBooks, and video training during our Presidents' Day Sale. Learn a new skill or get even better at what you already know with the highest-quality learning resources from the best trainers and instructors in the community. Use discount code *PD2018* during checkout, to secure your savings—and get free shipping within the U.S. Sale ends February 23. SHOP THE STORE *FREE SHIPPING* WITHIN THE U.S. * Discount code PD2018 confers a 55% discount off the list price of two or more eligible titles purchased on informit.com in a single transaction. Eligible titles include most print books, eBooks, Web Editions, and full-course video titles. Book + eBook bundles, book/eBook + video bundles, individual video lessons, Rough Cuts, Safari Books Online, non-discountable titles, titles on promotion with our retail partners, and any title featured as eBook or Video Deal of the Week are not eligible for discount. If any items are canceled or returned, and the order is no longer eligible for a volume-based discount code that was applied to the purchase, remaining items will be invoiced at the standard discounted price shown on the website. Offer ends 11:59 p.m. EST February 23, 2018. Discount may not be combined with any other offer and is not redeemable for cash. Offer subject to change. [image: Facebook] [image: Twitter] [image: YouTube] [image: Google+] InformIT, 800 East 96th Street, Indianapolis, IN 46240 © Pearson Education. All rights reserved. Unsubscribe -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeffrey.haemer at gmail.com Mon Feb 19 06:37:01 2018 From: jeffrey.haemer at gmail.com (Jeffrey S. Haemer) Date: Mon, 19 Feb 2018 06:37:01 -0700 Subject: [lug] Fwd: Save 55% During Our Presidents' Day Sale In-Reply-To: References: <0.1.A2.2BE.1D3A96CA95E896A.0@om-fen.rsys2.com> Message-ID: Thank you, Louis. On Mon, Feb 19, 2018 at 4:51 AM, Louis Krupp wrote: > FYI... > > ---------- Forwarded message ---------- > From: InformIT > Date: Mon, Feb 19, 2018 at 3:30 AM > Subject: Save 55% During Our Presidents' Day Sale > To: louis.krupp at gmail.com > > > Save 55% when you buy 2 or more books, eBooks, video training, or software > through February 23, 2018. Offer includes free U.S. shipping. > [image: InformIT] > > [image: Buy 2, Save 55% in the Presidents' Day Sale from InformIT] > > For a limited time, *buy 2, save 55%* > * > off the list price of books, eBooks, and video training during our > Presidents' Day Sale. Learn a new skill or get even better at what you > already know with the highest-quality learning resources from the best > trainers and instructors in the community. > > Use discount code *PD2018* during checkout, to secure your savings—and > get free shipping within the U.S. Sale ends February 23. > SHOP THE STORE > > *FREE SHIPPING* WITHIN THE U.S. > * Discount code PD2018 confers a 55% discount off the list price of two or > more eligible titles purchased on informit.com in a single transaction. > Eligible titles include most print books, eBooks, Web Editions, and > full-course video titles. Book + eBook bundles, book/eBook + video bundles, > individual video lessons, Rough Cuts, Safari Books Online, non-discountable > titles, titles on promotion with our retail partners, and any title > featured as eBook or Video Deal of the Week are not eligible for discount. > If any items are canceled or returned, and the order is no longer eligible > for a volume-based discount code that was applied to the purchase, > remaining items will be invoiced at the standard discounted price shown on > the website. Offer ends 11:59 p.m. EST February 23, 2018. Discount may not > be combined with any other offer and is not redeemable for cash. Offer > subject to change. > [image: Facebook] > [image: > Twitter] > [image: > YouTube] > > [image: > Google+] > > InformIT, 800 East 96th Street, Indianapolis, IN 46240 > > © Pearson Education. All rights reserved. > Unsubscribe > > > > > > > _______________________________________________ > Web Page: http://lug.boulder.co.us > Mailing List: http://lists.lug.boulder.co.us/mailman/listinfo/lug > Join us on IRC: irc.hackingsociety.org port=6667 channel=#hackingsociety > -- Jeffrey Haemer 720-837-8908 [cell], @goyishekop [twitter] *פרייהייט? דאס איז יאַנג דינען וואָרט!* -------------- next part -------------- An HTML attachment was scrubbed... URL: From bcarr at purgatoire.org Wed Feb 21 17:38:14 2018 From: bcarr at purgatoire.org (BC) Date: Wed, 21 Feb 2018 17:38:14 -0700 Subject: [lug] selinux In-Reply-To: <1517182067.3001918.1251124376.179A68B0@webmail.messagingengine.com> References: <1517100008.1647334.1250439216.732250C0@webmail.messagingengine.com> <1517182067.3001918.1251124376.179A68B0@webmail.messagingengine.com> Message-ID: <31f545da-7b9f-e4c2-f878-69bf8bf77b30@purgatoire.org> I'm converting a [bash] shell script to golang in an effort to learn to program in Go.  I'm having lots of success but this script statement has me confused:     _value="$(__get_jail_prop $_property default)" The puzzling word is 'default'.  __get_jail_prop is a function to which is passed the parameter $_property (defined elsewhere).  The function returns _value. But what does the word 'default' do?  I tried passing the word "default" to the Go-equivalent function and the program bombs.  So I don't think it is a parameter to be passed. Any thoughts on what that word does? TIA, Bucky -------------- next part -------------- An HTML attachment was scrubbed... URL: From blug-mail at duboulder.com Wed Feb 21 17:47:45 2018 From: blug-mail at duboulder.com (Lee Woodworth) Date: Wed, 21 Feb 2018 17:47:45 -0700 Subject: [lug] selinux In-Reply-To: <31f545da-7b9f-e4c2-f878-69bf8bf77b30@purgatoire.org> References: <1517100008.1647334.1250439216.732250C0@webmail.messagingengine.com> <1517182067.3001918.1251124376.179A68B0@webmail.messagingengine.com> <31f545da-7b9f-e4c2-f878-69bf8bf77b30@purgatoire.org> Message-ID: <2851074d-7731-14dc-79b5-cefacd019a2c@duboulder.com> On 02/21/2018 05:38 PM, BC wrote: > > I'm converting a [bash] shell script to golang in an effort to learn to program in Go. > I'm having lots of success but this script statement has me confused: > > >     _value="$(__get_jail_prop $_property default)" > > > The puzzling word is 'default'.  __get_jail_prop is a function to which is passed the > parameter $_property (defined elsewhere).  The function returns _value. > > But what does the word 'default' do?  I tried passing the word "default" to the > Go-equivalent function and the program bombs.  So I don't think it is a parameter to be > passed. I don't recall the string 'default' being special to the shell in an argument list. It looks to me like a second argument to the command/function. info bash usually has all the gory details What could happen is that since _property is not quoted, when it is empty then the command expansion is equivalent to: "$(__get_jail_prop default)" From bcarr at purgatoire.org Wed Feb 21 17:56:09 2018 From: bcarr at purgatoire.org (BC) Date: Wed, 21 Feb 2018 17:56:09 -0700 Subject: [lug] Bash shell script question In-Reply-To: <2851074d-7731-14dc-79b5-cefacd019a2c@duboulder.com> References: <1517100008.1647334.1250439216.732250C0@webmail.messagingengine.com> <1517182067.3001918.1251124376.179A68B0@webmail.messagingengine.com> <31f545da-7b9f-e4c2-f878-69bf8bf77b30@purgatoire.org> <2851074d-7731-14dc-79b5-cefacd019a2c@duboulder.com> Message-ID: <9e662b14-b3a0-95fb-09fd-0693dbf18a47@purgatoire.org> On 2/21/2018 5:47 PM, Lee Woodworth wrote: > On 02/21/2018 05:38 PM, BC wrote: >> >> >>      _value="$(__get_jail_prop $_property default)" >> >> > > I don't recall the string 'default' being special to the shell in an > argument list. It looks to me like a second argument to the > command/function. > > info bash usually has all the gory details Yeah, yeah - I've studied the bash man page (and what Google offers me) for months now.  I'm having to learn sh scripting alongside golang.  Bletch. > > What could happen is that since _property is not quoted, when it is > empty then > the command expansion is equivalent to: >   "$(__get_jail_prop default)" This I will have to chew on and study with the resources until I understand what you are saying...  From what I can tell of the script, $_property is never empty at this point.  I've been stepping through my Go version of the program and it this call that causes failure. Thanks.  Oh, in case you couldn't tell, I'm a hobbyist. -------------- next part -------------- An HTML attachment was scrubbed... URL: From blug-mail at duboulder.com Wed Feb 21 18:17:32 2018 From: blug-mail at duboulder.com (Lee Woodworth) Date: Wed, 21 Feb 2018 18:17:32 -0700 Subject: [lug] Bash shell script question In-Reply-To: <9e662b14-b3a0-95fb-09fd-0693dbf18a47@purgatoire.org> References: <1517100008.1647334.1250439216.732250C0@webmail.messagingengine.com> <1517182067.3001918.1251124376.179A68B0@webmail.messagingengine.com> <31f545da-7b9f-e4c2-f878-69bf8bf77b30@purgatoire.org> <2851074d-7731-14dc-79b5-cefacd019a2c@duboulder.com> <9e662b14-b3a0-95fb-09fd-0693dbf18a47@purgatoire.org> Message-ID: <0dab9af6-a83a-fb56-5740-a8d64b3eeb09@duboulder.com> On 02/21/2018 05:56 PM, BC wrote: > > > On 2/21/2018 5:47 PM, Lee Woodworth wrote: >> On 02/21/2018 05:38 PM, BC wrote: >>> >>> >>>      _value="$(__get_jail_prop $_property default)" >>> >>> >> >> I don't recall the string 'default' being special to the shell in an >> argument list. It looks to me like a second argument to the command/function. >> >> info bash usually has all the gory details > > Yeah, yeah - I've studied the bash man page (and what Google offers me) for months now. > I'm having to learn sh scripting alongside golang.  Bletch. > >> >> What could happen is that since _property is not quoted, when it is empty then >> the command expansion is equivalent to: >>   "$(__get_jail_prop default)" > > This I will have to chew on and study with the resources until I understand what you are > saying...  From what I can tell of the script, $_property is never empty at this point. > I've been stepping through my Go version of the program and it this call that causes failure. > > Thanks.  Oh, in case you couldn't tell, I'm a hobbyist. If you change your bash from _value="$(__get_jail_prop $_property default)" to _value="$(__get_jail_prop '$_property' default)" and the behavior changes it would suggest _property is an empty or blank string. at some point. Oh. And when building command lines for os.Cmd make sure you have separate slice elements for each arg so they will be passed as separate args to the command: property := "the prop string" tmpdir := "value for TMPDIR in the passed environment" cmd := &exec.Cmd{ Path: "/path/to/_get_jail_prop", Dir: "/cd/to/this/dir/, Args: []string{ "/path/to/_get_jail_prop", property, "default", }, Env: []string{ "PATH=/usr/local/bin:/usr/bin", "TMPDIR=" + tmpdir, }, } From jeffrey.haemer at gmail.com Wed Feb 21 18:20:29 2018 From: jeffrey.haemer at gmail.com (Jeffrey S. Haemer) Date: Wed, 21 Feb 2018 18:20:29 -0700 Subject: [lug] selinux In-Reply-To: <31f545da-7b9f-e4c2-f878-69bf8bf77b30@purgatoire.org> References: <1517100008.1647334.1250439216.732250C0@webmail.messagingengine.com> <1517182067.3001918.1251124376.179A68B0@webmail.messagingengine.com> <31f545da-7b9f-e4c2-f878-69bf8bf77b30@purgatoire.org> Message-ID: Bucky, Unless the shell script is being far too clever, the string "default" is being passed to __get_jail_prop() as a parameter. I might be able to help more if you included the function definition. On Wed, Feb 21, 2018 at 5:38 PM, BC wrote: > > I'm converting a [bash] shell script to golang in an effort to learn to > program in Go. I'm having lots of success but this script statement has me > confused: > > > _value="$(__get_jail_prop $_property default)" > > > The puzzling word is 'default'. __get_jail_prop is a function to which is > passed the parameter $_property (defined elsewhere). The function returns > _value. > > But what does the word 'default' do? I tried passing the word "default" > to the Go-equivalent function and the program bombs. So I don't think it > is a parameter to be passed. > > Any thoughts on what that word does? > > TIA, > > Bucky > > > _______________________________________________ > Web Page: http://lug.boulder.co.us > Mailing List: http://lists.lug.boulder.co.us/mailman/listinfo/lug > Join us on IRC: irc.hackingsociety.org port=6667 channel=#hackingsociety > -- Jeffrey Haemer 720-837-8908 [cell], @goyishekop [twitter] *פרייהייט? דאס איז יאַנג דינען וואָרט!* -------------- next part -------------- An HTML attachment was scrubbed... URL: From bcarr at purgatoire.org Wed Feb 21 18:25:14 2018 From: bcarr at purgatoire.org (BC) Date: Wed, 21 Feb 2018 18:25:14 -0700 Subject: [lug] Bash shell script question In-Reply-To: <0dab9af6-a83a-fb56-5740-a8d64b3eeb09@duboulder.com> References: <1517100008.1647334.1250439216.732250C0@webmail.messagingengine.com> <1517182067.3001918.1251124376.179A68B0@webmail.messagingengine.com> <31f545da-7b9f-e4c2-f878-69bf8bf77b30@purgatoire.org> <2851074d-7731-14dc-79b5-cefacd019a2c@duboulder.com> <9e662b14-b3a0-95fb-09fd-0693dbf18a47@purgatoire.org> <0dab9af6-a83a-fb56-5740-a8d64b3eeb09@duboulder.com> Message-ID: <3b8af6f5-64a7-e611-c264-35fc09a3e01d@purgatoire.org> My Go code doesn't look remotely like yours, but I do remember seeing an os.Cmd structure that takes the environment into account. I experimented and found I didn't need to use that form.  But I'll go back and take another gander at it, just to be sure.  Go's slices are wonderful, aren't they? On 2/21/2018 6:17 PM, Lee Woodworth wrote: > > Oh. And when building command lines for os.Cmd make sure you have > separate > slice elements for each arg so they will be passed as separate args > to the > command: > >     property := "the prop string" >     tmpdir := "value for TMPDIR in the passed environment" >     cmd := &exec.Cmd{ >         Path:       "/path/to/_get_jail_prop", >         Dir:        "/cd/to/this/dir/, >         Args:       []string{ >                        "/path/to/_get_jail_prop", >                        property, >                        "default", >                     }, >         Env:        []string{ >                        "PATH=/usr/local/bin:/usr/bin", >                        "TMPDIR=" + tmpdir, >                     }, >     } -------------- next part -------------- An HTML attachment was scrubbed... URL: From zlynx at acm.org Wed Feb 21 19:20:30 2018 From: zlynx at acm.org (Zan Lynx) Date: Wed, 21 Feb 2018 19:20:30 -0700 Subject: [lug] Bash shell script question In-Reply-To: <3b8af6f5-64a7-e611-c264-35fc09a3e01d@purgatoire.org> References: <1517100008.1647334.1250439216.732250C0@webmail.messagingengine.com> <1517182067.3001918.1251124376.179A68B0@webmail.messagingengine.com> <31f545da-7b9f-e4c2-f878-69bf8bf77b30@purgatoire.org> <2851074d-7731-14dc-79b5-cefacd019a2c@duboulder.com> <9e662b14-b3a0-95fb-09fd-0693dbf18a47@purgatoire.org> <0dab9af6-a83a-fb56-5740-a8d64b3eeb09@duboulder.com> <3b8af6f5-64a7-e611-c264-35fc09a3e01d@purgatoire.org> Message-ID: <20180222022029.GA28004@catbox.zlynx.org> 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 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. 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. The same is true of maps. Maps all hold internal pointers and need to be single-threaded or guarded by Mutex. Still, Go has way fewer problems than C or C++. I do like it. From bcarr at purgatoire.org Wed Feb 21 19:40:46 2018 From: bcarr at purgatoire.org (BC) Date: Wed, 21 Feb 2018 19:40:46 -0700 Subject: [lug] Bash shell script question In-Reply-To: <20180222022029.GA28004@catbox.zlynx.org> References: <1517100008.1647334.1250439216.732250C0@webmail.messagingengine.com> <1517182067.3001918.1251124376.179A68B0@webmail.messagingengine.com> <31f545da-7b9f-e4c2-f878-69bf8bf77b30@purgatoire.org> <2851074d-7731-14dc-79b5-cefacd019a2c@duboulder.com> <9e662b14-b3a0-95fb-09fd-0693dbf18a47@purgatoire.org> <0dab9af6-a83a-fb56-5740-a8d64b3eeb09@duboulder.com> <3b8af6f5-64a7-e611-c264-35fc09a3e01d@purgatoire.org> <20180222022029.GA28004@catbox.zlynx.org> Message-ID: 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: From zlynx at acm.org Thu Feb 22 00:26:11 2018 From: zlynx at acm.org (Zan Lynx) Date: Thu, 22 Feb 2018 00:26:11 -0700 Subject: [lug] Bash shell script question In-Reply-To: References: <1517100008.1647334.1250439216.732250C0@webmail.messagingengine.com> <1517182067.3001918.1251124376.179A68B0@webmail.messagingengine.com> <31f545da-7b9f-e4c2-f878-69bf8bf77b30@purgatoire.org> <2851074d-7731-14dc-79b5-cefacd019a2c@duboulder.com> <9e662b14-b3a0-95fb-09fd-0693dbf18a47@purgatoire.org> <0dab9af6-a83a-fb56-5740-a8d64b3eeb09@duboulder.com> <3b8af6f5-64a7-e611-c264-35fc09a3e01d@purgatoire.org> <20180222022029.GA28004@catbox.zlynx.org> Message-ID: <0fbca839-c7eb-0a9d-1903-4b40cbd0efe9@acm.org> On 2/21/2018 7:40 PM, BC wrote: > On 2/21/2018 7:20 PM, Zan Lynx wrote: >> 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. Well, it starts to add up. The situation I saw was a toy program I wrote that did something you can do with Awk, really. Read a big log file, maybe a few hundred megabytes? And store counts of how often words in field 6 appeared. And at the end output the list of words and counts. It used a LOT more memory than I expected and when I profiled it I realized that when I thought I was being clever by storing byte slices, I had actually prevented the garbage collector from collecting any of the file buffers. I just changed it to store regular strings instead, which Go copies out of byte slices and the problem went away. From bcarr at purgatoire.org Thu Feb 22 07:16:09 2018 From: bcarr at purgatoire.org (BC) Date: Thu, 22 Feb 2018 07:16:09 -0700 Subject: [lug] Go and Garbage Collection In-Reply-To: <0fbca839-c7eb-0a9d-1903-4b40cbd0efe9@acm.org> References: <1517100008.1647334.1250439216.732250C0@webmail.messagingengine.com> <1517182067.3001918.1251124376.179A68B0@webmail.messagingengine.com> <31f545da-7b9f-e4c2-f878-69bf8bf77b30@purgatoire.org> <2851074d-7731-14dc-79b5-cefacd019a2c@duboulder.com> <9e662b14-b3a0-95fb-09fd-0693dbf18a47@purgatoire.org> <0dab9af6-a83a-fb56-5740-a8d64b3eeb09@duboulder.com> <3b8af6f5-64a7-e611-c264-35fc09a3e01d@purgatoire.org> <20180222022029.GA28004@catbox.zlynx.org> <0fbca839-c7eb-0a9d-1903-4b40cbd0efe9@acm.org> Message-ID: On 2/22/2018 12:26 AM, Zan Lynx wrote: > >> I grew up in the era when 4k of RAM was a lot.  But now...  A >> trifling in the big scheme of things. > > Well, it starts to add up. The situation I saw was a toy program I > wrote that did something you can do with Awk, really. Read a big log > file, maybe a few hundred megabytes? And store counts of how often > words in field 6 appeared. And at the end output the list of words > and counts. > > It used a LOT more memory than I expected and when I profiled it I > realized that when I thought I was being clever by storing byte > slices, I had actually prevented the garbage collector from > collecting any of the file buffers. I just changed it to store > regular strings instead, which Go copies out of byte slices and the > problem went away. Oooops, guilty here too.  I will store this tidbit away for future reference. Thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeffrey.haemer at gmail.com Wed Feb 21 13:10:57 2018 From: jeffrey.haemer at gmail.com (Jeffrey S. Haemer) Date: Wed, 21 Feb 2018 13:10:57 -0700 Subject: [lug] Fwd: Two curiosity questions In-Reply-To: <15889ed5-148a-134a-419e-17280a477e59@scrye.com> References: <15889ed5-148a-134a-419e-17280a477e59@scrye.com> Message-ID: An FYI for folks who know Kevin & Nash. (Kevin is the host of the BLUG mailing list.) ---------- Forwarded message ---------- From: Kevin Fenzi Date: Wed, Feb 21, 2018 at 10:52 AM Subject: Re: Two curiosity questions To: "Jeffrey S. Haemer" [...] In other news here: a) Nash has been at the big vet hospital in portland the last few weeks. He had a mass on his kidney that burst, and they had to remoove the kidney and it's been a very slow recovery since then (he wont eat after that). To help defray his massive medical bills I started a gofundme: https://www.gofundme.com/medical-bills-for-nash Feel free to pass it on, just look at the cute nash pics or skip it. ;) Last night they put in a e-tube on him, and hopefully we can bring him home for real later today. [...] kevin -- Jeffrey Haemer 720-837-8908 <(720)%20837-8908> [cell], @goyishekop [twitter] *פרייהייט? דאס איז יאַנג דינען וואָרט!* -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 849 bytes Desc: not available URL: From blug-mail at duboulder.com Thu Feb 22 17:25:38 2018 From: blug-mail at duboulder.com (Lee Woodworth) Date: Thu, 22 Feb 2018 17:25:38 -0700 Subject: [lug] golang gotchas Message-ID: <6b9d3aa3-f457-b6ab-2034-df1dce4ed2b6@duboulder.com> Speaking of golang gotchas, when I started using go, nil handling was sometimes puzzling. Given these declarations: type T struct { a, b int } var ptr1 *T = nil var ptr2 *T /* effectively (*T) (0) */ var ifval1 interface{} = T{ a: 1, b: 2 } var ifval2 interface{} = &T{ a: 3, b: 4 } var ifval3 interface{} = nil var ifval4 interface{} = ptr1 The output of fmt.Printf using format specs of "%T/%p %v" for the values and "%t" for the comparisons: ptr1=*main.T/0x0 ptr2=*main.T/0x0 ptr1 == ptr2 is true ptr1 == nil is true ifval1=main.T/%!p(main.T={1 2}) {1 2} ifval2=*main.T/0xc420018100 &{3 4} ifval3=/%!p() ifval4=*main.T/0x0 ifval3 == nil is true ifval4 == nil is false The quirky thing is ptr1 = nil; ifval4 = ptr1 but ptr1 == nil and ifval4 != nil This is due to interfaces holding a type and a value and untyped nil constant conversion. ptr1 = nil effectively converts the untyped nil to (*T) (0) ifval3 = nil converts the untyped nil to a special value "nil" with a special system-defined type ifval4 = ptr1 stores the type *T and ptr1's value (0) which is not the same as the special "nil" value You can see that interface{} is storing a value and not a pointer from ifval1. Its type is T, not *T and the %p format uses an error display instead of printing an address. Another quirk is that if type T had the pointer-based method M1 defined on it: func (t *T) M1 () { fmt.Println ("ok") } then ptr1.M1 () is a perfectly valid method call and won't panic since M1 does not dereference its receiver argument.