<story><title>Mistakes C/C++ Devs make writing Go</title><url>https://about.sourcegraph.com/go/gophercon-2018-5-mistakes-c-c-devs-make-writing-go</url></story><parent_chain></parent_chain><comment><author>ktpsns</author><text>Here&amp;#x27;s a newbie&amp;#x27;s bit off topic question: As a C++ dev who wants to write &amp;quot;slightly less low-level code&amp;quot;, should I go for RUST or GO? My intuition says Rust is more like a safer version of C++ while Go is more half way to Python&amp;#x2F;Julia. Do you agree with this sloppy assessment?&lt;p&gt;(Please, don&amp;#x27;t start a religious war on programming languages. We are all grown ups)</text></comment>
<story><title>Mistakes C/C++ Devs make writing Go</title><url>https://about.sourcegraph.com/go/gophercon-2018-5-mistakes-c-c-devs-make-writing-go</url></story><parent_chain></parent_chain><comment><author>shoo</author><text>re: &amp;quot;# channels &amp;lt; # goroutines&amp;quot;&lt;p&gt;&lt;pre&gt;&lt;code&gt;  func doSomethingTwice() error {
      &amp;#x2F;&amp;#x2F; Issue occurs below
      errc := make(chan error)
  
      go func() {
          defer fmt.Println(&amp;quot;done wth a&amp;quot;)
          errc &amp;lt;- doSomething(&amp;quot;a&amp;quot;)
      }()
      go func() {
          defer fmt.Println(&amp;quot;done with b&amp;quot;)
          errc &amp;lt;- doSomething(&amp;quot;b&amp;quot;)
      }()
      err := &amp;lt;-errc
      return err
  }
&lt;/code&gt;&lt;/pre&gt;
&amp;gt; When one routine writes to the channel, the program exits and the other goroutine is lost, building up memory use as a results&lt;p&gt;I&amp;#x27;m not very familiar with go, but my guess would be that since the two goroutines send to an unbuffered channel that is read at most once, the &amp;quot;slower&amp;quot; of the two goroutines will sit there blocking attempting to send to a channel that will never be read. So this would &amp;quot;leak&amp;quot; a goroutine that would consume resources while the process was still running, but it doesn&amp;#x27;t have anything to do with the program exiting.&lt;p&gt;&lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;golang.org&amp;#x2F;ref&amp;#x2F;spec#Channel_types&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;golang.org&amp;#x2F;ref&amp;#x2F;spec#Channel_types&lt;/a&gt;&lt;p&gt;&lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;golang.org&amp;#x2F;ref&amp;#x2F;spec#Send_statements&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;golang.org&amp;#x2F;ref&amp;#x2F;spec#Send_statements&lt;/a&gt;&lt;p&gt;&amp;gt; How do we fix this? We simply increase the number of channels to 2&lt;p&gt;The fix is okay but the language is a bit hazy, there&amp;#x27;s still only one channel, but now it&amp;#x27;s a buffered channel with capacity to hold up to 2 messages, so the two goroutines don&amp;#x27;t need to block waiting for a receiver to be ready to synchronously receive the message they are sending.</text></comment>