HUIJZER.XYZ

Running code in blog posts is probably a bad idea

2025-01-25

One of my favorite things to do is to automate as much as possible. So when I started writing blog posts, I thought it would be a good idea to run the code in my blog posts automatically. For example, I would add blogs with cool code and visualizations and then run this code upon each push to the repository via CI. I even made a package for it called PlutoStaticHTML.jl.

What PlutoStaticHTML.jl allows you to do is to write your blog posts in Pluto notebooks (Pluto.jl is like Jupyter notebooks but for the Julia language). Then, you can setup CI such that the code will be executed each time you push to the repository and the output will be embedded in the blog post.

Like this, you write this Julia code:

function f(x)
    x + x
end

f(1)

and get the following output:

2

Now you could copy-paste this output, but that's not very convenient. Automating this is a great idea, right?

Well, in theory it is but in practice it's probably a bad idea. The problem is that blog posts, like most writing, are ephemeral. Meaning that most blog posts will slowly become more and more outdated and irrelevant (and that's okay; even academic papers have this problem). However, if you decide to run the code in your blog posts automatically, then you are forced to maintain the code. Even worse, breaking changes might lead you to be unable to push new changes to your blog without fixing the code first.

It's probably not worth it. Just write the code, copy-paste the output and call it a day. This way, you still have the code available to you and can still read it when you need it later. And if you don't read it, then that's no problem since you're not maintaining it anyway.

As long as your blog clearly mentions the data of publication, then people will probably not mind outdated code either.