The magic of scope guards

submited by
Style Pass
2023-05-26 18:00:09

Apart from explaining why, I also want to explore one specific side of them that I have never read about directly: their effect on compile times.

Let me start todays exploration with a bit of a rant. What I am talking about today, and what I refer to as “scope guards” is often called the RAII pattern. That stands for “resource acquisition is initialization”, and I believe its a horrible acronym. What are we initializing? Are we even acquiring anything? Well maybe when we are talking about locks yes, but otherwise?

Apart from that, I am also very much against computer-science-speak. More specifically, hiding otherwise easy to understand concepts behind complicated-sounding nomenclature. In computer-science-speak, this concept is called “affine types”. What the hell does “affine” even mean? I am not a native speaker, but according to a dictionary, it is also translated as “affin” in my native german. Well thanks for nothing. Another translation is “verwandt”, which means “related” in english. Okay, that does not help either.

These “affine types” are also related (see what I did there?) to “linear types” that are being discussed in the Rust community right now. Another word that on its own does not convey any meaning.

Leave a Comment