GopherCon Europe 2020: André Eriksson - Automatically Translating Python Source to Idiomatic Go Code

28:12 276 views 80% Published 6 months ago

About the talk:
Manually converting source code in one language to another is laborious. Existing approaches, often dubbed “transpilers” the JavaScript community, are insufficient for this purpose as they (1) produce code intended for machines, not humans; (2) work in the direction of going from stronger type systems to equivalent or weaker type systems.

This talk presents an approach that addresses both of these concerns. I will present how we successfully converted a project of several thousand lines of dynamically typed Python code into human-readable, fully typed, idiomatic Go source code. The program is built entirely in Go and consists of a Python parser, a static analyzer that does full-program analysis to understand what type(s) each Python object may be, and an output stage that converts this representation into idiomatic Go code.

The talk will show the audience how the program works and how to overcome the challenges of going from dynamically typed Python source code to fully typed Go source code. It will give the audience a better understanding of parsing source code into ASTs, how to analyze them and rewrite them to perform modifications, and lastly how to use Go’s excellent source code formatting to output properly formatted Go source code at the end.

About the speaker:
André Eriksson is a (@TheSwedeheart) Staff Software Engineer @ Spotify and have been writing Go since 1.0. On the side I’m working on a new approach to Serverless through a Backend-as-a-Service platform for Go called Encore.


Link Original video