Thursday, December 25, 2014

Scratching an itch with Golang

I frequently find mp3's of conference talks, or discussions online that I want to listen to, but listening to plain mp3's posted on the internet on my phone is cumbersome. I'd really prefer the mp3's wrapped up in a podcast. My phone's podcast application is much more feature rich than my phones mp3 player. I decided that it was time to scratch this itch and write a program that would take directories of mp3s and turn them into ad-hoc podcasts.

I decided to write the program using Go. The last time I really wrote in Go I was writing C/C++ code for my day job and Go felt magical. Now I'm using Python so I thought it would be interesting to see how my perceptions of the language would change now that I'm accustomed to writing in Python. So here is what I've discovered or rediscovered about Go after not having not used it for a while.

  1. Go's support for concurrency still feels magical, and the tools for detecting data races are wonderful. With Python I've avoided concurrency altogether and instead opted to use multiple Python processes. With C/C++ I would use threads, but do so knowing that sometime in the future I or whomever maintained the code would encounter a deadlock, or a data race issue.
  2. I felt was less productive in Go than I would have been in Python. As I tried to figure out why I thought about three issues. First I realized that I'm simply not as familiar with Go's standard packages as I am with Python's so I spend more time looking up standard functions. The second is that Go forces me to decide whether to handle or ignore errors and I feel guilty ignoring errors. With Python it's much easier to ignore (intentionally or not) exceptions that are raised. With Go most of the time I either assign returned errors to a variable and handle it or assign it to '_' and am constantly reminded of the ignored error. Third I think that Go may simply be more verbose than Python.
  3. The ability to run and modify examples directly from Go's documentation pages is really helpful. With python when I want to experiment with an API, I would bring up a REPL. That's great but being able to do it directly from the documentation page with Go is more convenient because all of the setup code has already been written.
  4. Spending time formatting code in Python feels like a waste of time when I'm accustomed to using Go's automatic code formatting.
The code for ad-hoc podcasts is on github. The code is not not pretty nor well factored, but it's working (on my machine). Patches of course are welcome.