I’m a Rust programmer but I would call it scope-based or scope-bound resource management, a popular alternative term in the C++ community.
> I would call it scope-based or scope-bound resource management RAII isn't about scope, it's about lifetimes that can persist beyond the instantiating scope. More like object-bound resource management.
Ask HN: What should have been the term for RAII?
51–60 of 62 posts
Re: Ask HN: What should have been the term for RAII?
#52Earlier quoted context omitted.
> I would call it scope-based or scope-bound resource management RAII isn't about scope, it's about lifetimes that can persist beyond the instantiating scope. More like object-bound resource management.
Scope is a necessary part of it too though. There’s always going to be one owning scope for an object in Rust (unless you’re using Rc) and that scope is responsible for calling the destructor. You can change which scope is responsible by moving it, but scope is still important. Without scope being an implicit part of resource management, you have a feature like try/finally or with in Python.
Re: Ask HN: What should have been the term for RAII?
#53Re: Ask HN: What should have been the term for RAII?
#54I’m a Rust programmer but I would call it scope-based or scope-bound resource management, a popular alternative term in the C++ community.
> I would call it scope-based or scope-bound resource management RAII isn't about scope, it's about lifetimes that can persist beyond the instantiating scope. More like object-bound resource management.
Re: Ask HN: What should have been the term for RAII?
#55Resource Encapsulation
Re: Ask HN: What should have been the term for RAII?
#56Earlier quoted context omitted.
Scope is a necessary part of it too though. There’s always going to be one owning scope for an object in Rust (unless you’re using Rc) and that scope is responsible for calling the destructor. You can change which scope is responsible by moving it, but scope is still important. Without scope being an implicit part of resource management, you have a feature like try/finally or with in Python.
You're still trying to make this about rust without bothering to learn what the C++ users here are talking about. I'm not sure what to tell you.
Re: Ask HN: What should have been the term for RAII?
#57Earlier quoted context omitted.
You're still trying to make this about rust without bothering to learn what the C++ users here are talking about. I'm not sure what to tell you.
Rust got the concept from C++ and it’s not a C++-specific concept, despite having originated there. You seem to have some fundamental disagreement with what I’m saying that you’ve yet to identify. What does RAII look like without scope, if it’s not about scope? How would RAII work in a dynamically scoped language?
Re: Ask HN: What should have been the term for RAII?
#58Earlier quoted context omitted.
> I would call it scope-based or scope-bound resource management RAII isn't about scope, it's about lifetimes that can persist beyond the instantiating scope. More like object-bound resource management.
Many RAII objects really are tied to a simple scope - such as std::lock_guard. So it's not just about persisting beyond the initial scope. I don't recall the word "lifetime" being used in the C++ world before Rust came along. The word "scope" was often used in the same way we talk about lifetimes now. And if you think of the space between an object's constructor and its destructor as a scope, then anything that it ow…
"Lifetime" is a normative term in ISO C. In the 1999 standard, it is given as: "The lifetime of an object is the portion of program execution during which storage is guaranteed to be reserved for it. An object exists, has a constant address, and retains its last-stored value throughout its lifetime." (6.4.2 Storage Durations of Objects)
"Lifetime" appears three times in the Index of the 1988 edition of Compilers: Principles, Techniques and Tools by Aho, Sethi and Ullman (a.k.a. the Red Dragon Book).
Lifetime, of a temporary 480
Lifetime, of an activation 391, 410
Lifetime, of an attribute 320-322, 324-329
Re: Ask HN: What should have been the term for RAII?
#59Earlier quoted context omitted.
Many RAII objects really are tied to a simple scope - such as std::lock_guard. So it's not just about persisting beyond the initial scope. I don't recall the word "lifetime" being used in the C++ world before Rust came along. The word "scope" was often used in the same way we talk about lifetimes now. And if you think of the space between an object's constructor and its destructor as a scope, then anything that it ow…
> I don't recall the word "lifetime" being used in the C++ world before Rust came along. "Lifetime" is a normative term in ISO C. In the 1999 standard, it is given as: "The lifetime of an object is the portion of program execution during which storage is guaranteed to be reserved for it. An object exists, has a constant address, and retains its last-stored value throughout its lifetime." (6.4.2 Storage Durations of O…
Re: Ask HN: What should have been the term for RAII?
#60BTW, a lot of people in this thread compare destructors to Java's try-with-resource (similarly, C#'s using), or Go's defer. Here's one important difference: Destructors work in standard data structures. If for whatever reason you want to build a map >, 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.