Live data from Hacker News

Ask HN: What should have been the term for RAII?

news.ycombinator.com

41–50 of 62 posts

Re: Ask HN: What should have been the term for RAII?

#41
BTW, 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#.

Re: Ask HN: What should have been the term for RAII?

#42

Constructor Acquires, Destructor Releases.

In C++, if the construction fails (with an exception), no other member function - not even the destructor - gets called and the resource is not acquired.

This is one reason many people think exceptions in C++ are harmful, they cause unclear implicit behavior. Much better to handle a failure explicitly outside the constructor

Re: Ask HN: What should have been the term for RAII?

#43
The most important part for me is not construction,but the guaranteed destruction. So what about:

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++

Re: Ask HN: What should have been the term for RAII?

#44
post #4

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.

Re: Ask HN: What should have been the term for RAII?

#46
Wow, such good ideas here. I guess no one is keen on my "RAPR" proposal :) But just to reflect a bit more, I think my curiosity/confusion stems from the "is initialization" wording, and how the word "initialization" in the context of C++ will imply a guaranteed freeing step?

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.

Re: Ask HN: What should have been the term for RAII?

#47
post #24

Earlier quoted context omitted.

C++ _isn't_ RAII. RAII is a design pattern you can apply, leveraging C++ language features, in C++ in certain cases to avoid a certain class of bugs.

Well sure but I would assume the pattern would be consistently implied in the standard library, no?

I'm not an expert, but I would so no, it's not. The point of learning to implement with RAII, in the context of C++, is so that one will apply it to use C++ in a more resource safe way. It will help avoid the bugs that the language will inherently allow if the programmer is not being otherwise being careful.

Re: Ask HN: What should have been the term for RAII?

#48

The most important part for me is not construction,but the guaranteed destruction. So what about: 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++

Nice!!

Re: Ask HN: What should have been the term for RAII?

#49

Earlier quoted context omitted.

In C++, if the construction fails (with an exception), no other member function - not even the destructor - gets called and the resource is not acquired.

This is one reason many people think exceptions in C++ are harmful, they cause unclear implicit behavior. Much better to handle a failure explicitly outside the constructor

This is one reason I use Pascal

If the constructor throws an exception, the destructor is called immediately.

Post reply on HN