What would be a better terminology?
As I’ve been learning modern C++, I admit that I’ve struggled to understand why these terms make sense. To me, I think of it like “Resource Acquisition Promising Release”. Does this betray that I am not truly understanding Strourstrup’s principle?
RAII isn't about scope, it's about lifetimes that can persist beyond the instantiating scope. More like object-bound resource management.
The earliest mention of this idea (CADR / CADRe) I’ve found is from 2012: https://groups.google.com/a/isocpp.org/g/std-proposals/c/Una...
Here's one important difference: Destructors work in standard data structures. If for whatever reason you want to build a map<string, list<fstream>>, and the map goes out of scope, all files are correctly closed. (Rust's drop semantics work the same way.) That's a lot more work in Java or C#.
Yes, that means they hang around a lot longer, and that's sometimes problematic, but that's the GC way.
For resources like memory, where it’s merely a question of performance, I would agree. But some resources have correctness implications. Files, for example, you often want to close deterministically. It’s simply a terrible experience if a user can’t save because a file handle from a previous operation still lingers in a GC queue somewhere.
That’s also the reason why language features like try-with-resources were added in the first place.
Resource Is Getting Guaranteed to End up Destructed.
I try to have RIGGED as backronym, but the words are not completely right. Even so, the slogan could work like this: Prefer using RIGGED resources in C++
I've tried reconciling how its defined here:
https://en.cppreference.com/w/cpp/language/initialization
However, it seems like wording describing ideas around how a resource is created, and not how it's completed.
> Resource Acquisition Is Initialization or RAII, is a C++ programming technique[1][2] which binds the life cycle of a resource that must be acquired before use (allocated heap memory, thread of execution, open socket, open file, locked mutex, disk space, database connection—anything that exists in limited supply) to the lifetime of an object.
I’d crib the name from Rust, this is ownership, where the object owns the resource.
Also, see related video here
CppCon 2015: Andrei Alexandrescu “Declarative Control Flow"
https://youtu.be/WjTrfoiB0MQ?t=1046