BXG Blog

The Joy of Backwards Compatibility

Today I updated my blog generator for the first time since around 2015. After I missed a couple of releases, I had been afraid to touch it, since you never know how much of a time sink a major upgrade will be. Now that CentOS 7 supports python 3 and python 2 is officially a zombie, I figured I better get things back into a supportable state.

Well, I have good news: The Pelican folks have done an amazing job with backwards compatibility. Other than changing a few paths to point to the new installation, not a single thing broke!

On the topic of backwards compatiblity, I also decided to rename my content files to include the date. I wrote a quick bash one-liner that extracted the Date header from each article and renamed the file to include the date portion at the front of the name. After regenerating the site into a temporary directory, everything initially looked fine, so I updated the main site.

That was easy, right? Not so fast: I suddenly had a bunch of broken links. Pelican allows you to cross-link articles by referring to the local file name, and I had forgotten this when I renamed all the files. Luckily there weren’t very many, so it was easy to grep for {filename} and fix them all by hand. The externally visible URL paths hadn’t changed, since I learned that lesson during the previous blog upgrade.

There are a couple of possible lessons here:

  • Hooray for good backwards compatibility! Pelican made my life a lot easier with such a smooth upgrade.
  • Hooray for the power of the shell! I was able to rename all my files with a bash one-liner and fix all the broken links with a couple of grep and vim calls. No real programming needed.
  • Hooray for encapsulation! By keeping the public URL paths separate from the local filenames, I don’t have to update any external links after renaming everything.
  • This is an instance where a database might have helped. There would be no need to rename files if I could trivially sort database queries by date. Since I can’t put every piece of metadata into the filename, this might apply again in the future. On the other hand, it’s a lot easier to move files around (or write a quick perl script) than to redesign a database schema if it turns out not to include an important piece of data.

If you have comments or questions about this post, please send an email. Be sure to leave the subject line alone, or your email is likely to be caught by spam filters.

Computers python