DEV-DIARIES
Dev Diary 2020-07-08
The new CoffeeOutside bot has finally managed to successfully call its first location. Sure, the rewrite took learning 2 programming languages and several hours of my life that I’ll never get back. But the satisfaction of when it finally worked made it worth it.
The story of this rewrite is that in early 2019 the Python code was bit-rotting, and I wasn’t feeling like I wanted to spend the effort of getting it moved to Python 3, since setting up the environment and testing it was a bit of a pain. I try to avoid rewrites unless there’s serious tech debt or design flaws (some would argue not to rewrite at all). “Ahah, I’ll rewrite it in Go, should be easy!” I was just starting to learn Go at the time, and decided to blow past the “hello world” stage into “move all my crappy scripts to Go” stage.
Now normally when I’m learning a language I try to write a whole bunch of test programs, so that I really understand how everything works. Once I’m confident, then I’ll use it for something meaningful, and all those little ugly examples rot on my hard drive, never seen ever again. Now here’s the thing about the CoffeeOutside bot: when it fails, it fails publicly and requires me to drop everything to remedy the situation. Are there tests? Yes, but they can only go so far, as Ted Unangst just wrote about, and when you’re still wrestling with the concepts of the language, they won’t be as effective as they could be when you know what the heck you’re doing.
After several failures, I shelved the Go rewrite. “Not worth the stress!” I got to work updating the Python code from 2 to 3, and while there was a bit of stumbling the code was at least good until the next breaking Python release. A few fixes here, a few fixes there, but it weighed on my mind that there was a bunch of features I wanted to add, and I still wanted something that was easy to drop into new environments (like a Docker container).
Along came Rust. Rust is great. Well, really great for some things, I should say. I was so sure that Rust would be perfect for the new CoffeeOutside bot. There’s many parts they get right, but then there’s the parts where it leaves you head scratching. And I don’t mean “I don’t know what’s going on,” but “what series of problems led them to this approach?” It’s frustrating when you have to try on 3 different modules trying to find a library that can do the thing that should be fairly simple. And because of the lack of standard libraries, my simple little executables pull in a ton of dependencies (or as I like to think of them, “moving parts that will break someday”). I tried 4 different libraries for the command line flags. You know how many I wanted to test? 1. And crates has plenty of things for Twitter, but you’ll have to dig, because squatters grabbed all the good names for libraries that hardly work anymore. I really love Rust ’the language’ and Rust ’the developer environment,’ and I know there’s still going to be Rust projects in my future. But the Rust library situation is a mess, and I’ve got zero desire to yak shave a new OpenWeatherMap library into existence.
I’m not sure what made me return to the Go rewrite. But maybe after the hard work of wrapping my head around Rust, Go finally seemed to click. Maybe it also helped that I got YouCompleteMe working in Vim. Type systems are way easier to work with when you’ve got a language server pointing out problems in real-time as well. Maybe my problem with Go was an editor problem? Whatever the case, it was much easier to find the defects in the Go rewrite, and after a few evenings I had something I was happy with. After some overdue server shuffling, it was ready for prime time.
Will I continue to fuss over the new bot? Absolutely, but now I can start to add all the features I was meaning to add years ago, so I feel a sense of relief that the hard part is now done. All this mental effort for a magic 8-ball that decides where people should drink coffee ;-)