<story><title>Experience report on a large Python-to-Go translation</title><url>https://gitlab.com/esr/reposurgeon/blob/master/GoNotes.adoc</url></story><parent_chain></parent_chain><comment><author>mappu</author><text>Here&amp;#x27;s another experience report: I ported a small 1 KLOC PHP project to Go this week (in some spare time between large C++ compile times). The primary goal was to reduce the number of supported languages we use.&lt;p&gt;The port happened in the mechanical line-by-line way, copying each PHP file to a *.go and fixing all the syntax. The project was small enough that automation wasn&amp;#x27;t interesting.&lt;p&gt;I agree with the &amp;quot;1&amp;#x2F;3 time spent debugging the result&amp;quot;. Another complicated facet was the lack of insertion-order preserving maps, that PHP applications end up relying on heavily. The error&amp;#x2F;exception impedance mismatch was not a problem in practice at all.&lt;p&gt;According to cloc, the original PHP project (excluding vendor) is 1.0 KLOC, the resulting Go application is 1.2 KLOC. I imagined Go would have been more verbose than this, but actually most lines remained 1:1 conversions, and the Go standard library happened to cover a lot of small utility functions that had to be separately written in PHP (e.g. for string suffix matching).&lt;p&gt;Another interesting point is the number of comment lines in cloc appeared to drop dramatically, since real type annotations are much less verbose than PHPDoc.</text></comment>
<story><title>Experience report on a large Python-to-Go translation</title><url>https://gitlab.com/esr/reposurgeon/blob/master/GoNotes.adoc</url></story><parent_chain></parent_chain><comment><author>melling</author><text>Go is probably more verbose because it’s missing List comprehensions, for example.&lt;p&gt;It needs map, filter, reduce to reduce line count. Swift, while probably not as performant as Go, makes writing in a more Pythonic style.&lt;p&gt;&lt;pre&gt;&lt;code&gt;   [1,2,3,4,5,6,7,8,9].filter {$0 % 2 == 0}.map {$0 * 2}.reduce(0, +)

   [&amp;quot;550&amp;quot;, &amp;quot;a&amp;quot;, &amp;quot;6&amp;quot;, &amp;quot;b&amp;quot;, &amp;quot;42&amp;quot;, &amp;quot;99&amp;quot;, &amp;quot;100&amp;quot;].compactMap{Int($0)}.filter {$0 &amp;lt; 100}
&lt;/code&gt;&lt;/pre&gt;
&lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;github.com&amp;#x2F;melling&amp;#x2F;SwiftCookBook&amp;#x2F;blob&amp;#x2F;master&amp;#x2F;functional.md&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;github.com&amp;#x2F;melling&amp;#x2F;SwiftCookBook&amp;#x2F;blob&amp;#x2F;master&amp;#x2F;functio...&lt;/a&gt;</text></comment>