5 ms·
I'm pretty sure my brother doesn't know what RAII is, but he's a way better C++ developer than me. The principle of scope, and scope-bound (and scope-bound obj
by orwin 3y ago
I'm pretty sure my brother doesn't know what RAII is, but he's a way better C++ developer than me.
The principle of scope, and scope-bound (and scope-bound objects) really took of recently, and i'm pretty sure a better name than RAII exists now (especially since RAII doesn't mention deletion, and resource deletion is litterally the point of RAII).
He might know about SFINAE, i didnt (but i never got into C++ metaprogramming, and he did).
- zabzonk 3y ago> The principle of scope, and scope-bound (and scope-bound objects) really took of recently "recently"? - you are joking. i suspect that neither you nor your brother know much at all about c++. RAII and scope are both core ideas in c++ and always have been.
- Merad 3y ago> RAII and scope are both core ideas in c++ and always have been. I would say that's debatable. RAII definitely dates back to the earliest days of C++, but you don't have to know it in order to use the language. Even today there are many professional C++ devs who've never really learned RAII because they write C with classes style code. I first started learning C++ about 20 years ago and IIRC at the time usage of RAII was still in the minority but there was real momentum towards it being considered the "right" way to do C++.
- zabzonk 3y agowell, i started using c++ in the late-80s, and even back then RAII (possibly not under that (bad, IMHO) name) was widely seen as an important feature of the language. how else could you implement a string class (which you had to do yourself back then)?
- Merad 3y ago> how else could you implement a string class I'm not claiming that it's good C++ code (or good code by any measure) but I imagine those "C with classes" devs would do something like: my_string* s = new my_string(); s->initialize("hello world"); // ... s->destroy(); delete s;
- zabzonk 3y agowell, i have seen a lot of very bad c++ code in my time, but nothing like this.
- gpderetta 3y agoThe deletion (or better release as RAII is not just for memory) is implied in the acquisition part. Also RAII is not (just) about scope, but bout tying, recursively, the lifetime of a resource to another one. You might even have manual destructor calls at the bottom of the tree, the rest would still be RAII. If it was just about scope, higher order functions would be sufficient.