Experience report on a large Python-to-Go translation
Pretty interesting.  It is scary to make your &quot;learn a new language&quot; task to port 14,000 lines of code, but with that in mind, this all seems to have gone well.  Some random thoughts:<p>&gt; I had to write my own set-of-int and
set-of-string classes<p>map[int]struct{}, map[string]struct{}<p><pre><code>   ints[42] = struct{}{} &#x2F;&#x2F; insert
   delete(ints, 42) &#x2F;&#x2F; delete 
   for i := range ints { ... } &#x2F;&#x2F; iterate
   if _, ok := ints[42]; ok { ... } &#x2F;&#x2F; exists?
</code></pre>
&gt; Catchable exceptions require silly contortions<p>I am not sure why go has panic&#x2F;recover, but it&#x27;s not something to use.  panic means &quot;programming error&quot;, recover means &quot;well, the code is broken but I&#x27;m just a humble generic web framework and I guess maybe the next request won&#x27;t be broken, so let&#x27;s keep running&quot;.  It is absolutely not for things like &quot;timeout waiting for webserver&quot; or &quot;no rows in the database&quot; as other languages use exceptions for.  For those, you return an error and either wrap it with fmt.Errorf(&quot;waiting for webserver: %w&quot;, err) or check it with errors.Is and move on.  Yup, you have to remember to do that or your program will run weirdly.  It&#x27;s just how it is.  There is not something better that maybe with some experimentation you will figure out.  You have to just do the tedious, boring, and simple thing.<p>I have used recover exactly once in my career.  I wrote a program that accepted mini-programs (more like rules) via a config file that could be reloaded at runtime.  We tried to prove them safe, but recover was there so that we could disable the faulty rule and keep running in the event some sort of null pointer snuck in.  (I don&#x27;t think one ever did!)<p>&gt; Pass-by-reference vs. pass-by-value<p>I feel like the author wants []*Type instead of []Type here.<p>&gt; Absence of sum&#x2F;discriminated-union types<p>True.  Depending on what your goals are, there are many possibilities:<p><pre><code>   type IntOrString struct { i int; s string; iok, sok bool }
   func (i IntOrString) String() (string, error) { if i.sok { return i.s, nil } else { return &quot;&quot;, errors.New(&quot;is not a string&quot;) }}
   func NewInt(x int) IntOrString { return IntOrString{i: x, iok: true} }
   ...

</code></pre>
This uses more memory than interface{}, but it&#x27;s also very clear what you intend for this thing to be.<p>I will also point out that switch can bind the value for you:<p><pre><code>   switch x := foo.(type) {
   case int:
      return x + 1
   case string:
      i, err := strconv.Atoi(x)
      return i + 1
   }
</code></pre>
And that you need not name types merely to call methods on them:<p><pre><code>   if x, ok := foo.(interface { IntValue() int }); ok { return x.IntValue() }

</code></pre>
You can also go crazy like the proto compiler does for implementations of &quot;oneof&quot; and have infinite flexibility.  It is not very ergonomic, but it is reliable.<p>&gt; Keyword arguments<p><pre><code>   type Point struct { X, Y float64 }

   func EuclideanDistance(a, b Point) float64 { ... }

   EuclideanDistance(Point{X: 1, Y: 2}, Point{3, 4})
</code></pre>
&gt; No map over slices<p>This one is like returning errors.  You will press a lot of buttons on your keyboard.  It is how it is.<p>I personally hate typing the average &quot;simple&quot; for loop:<p><pre><code>   func fooToInterface(foos []foo) []interface{} {
       var result []interface{}
       for _, f := range foos {
           result = append(result, f)
       }
       return result
   }
</code></pre>
But it&#x27;s also not that hard.  I used to be a Python readability reviewer at Google.  I always had the hardest time reading people&#x27;s very aggressive list comprehensions.  It was like they HAD to get their entire program into one line of code, or people wouldn&#x27;t think they were smart.  The result was that the line became a black box; nobody would read it, it was just assumed to work.<p>I really like seeing the word &quot;for&quot; twice when you&#x27;re iterating over two things.