Donation Appeal
Image

hacker news

  • Australia
Raised So Far CAD 0
0% Complete
Target : CAD 5,000

About Appeal

Learning Go by porting a medium-sized web backend from Python
November 2017

Summary: To learn Go, I ported the backend of a small site I run from Python to Go, and had a fun, pain-free experience doing so.

I’ve been wanting to learn Go for a while now: I like the philosophy of a language that’s small, has a gentle learning curve, and compiles very fast (for a statically-typed language). What pushed me over the line to actually go and do it was seeing more and more fast, robust tools that are written in Go – Docker and ngrok are two I’ve used recently.

The philosophy of Go is not to everyone’s taste (no exceptions, no user-defined generics, etc), but it fit my mental model well. Simple, speedy, does things the obvious way. During the port, I was especially impressed with how robust the standard library and tooling was.

The port
I started writing a couple of 20-line command line scripts, but I wasn’t really getting into the language or ecosystem in a big way. So I wanted to do a medium-sized project in it, and decided porting the backend for my GiftyWeddings.com website was the way to go.

It was originally about 1300 lines of Python code, using Flask, WTForms, Peewee, SQLite, and a few other libraries for S3, image resizing, etc.

For the Go port, I wanted to use as few external dependencies as reasonably possible, so that I could learn more of the language and be exposed to as much of the Go standard library as possible. In particular, Go has great HTTP libraries, and I didn’t want to pull in a web framework. However, I used 3rd party libraries for S3, Stripe, SQLite, password handling, and image resizing.

Due to Go’s static typing and because I was using fewer libraries, I expected that the code would end up being more than twice as many lines of code. However, it was only 1900 lines of Go (about 50% more than the 1300 lines of Python).a
The porting effort was very smooth, and a lot of the business logic was almost mechanical, line-for-line porting of the original Python. I was surprised how well many Python concepts translate to Go, right down to the things[:20] slice notation.

Recent Donors 0