4 ms·
> Conflation of resource allocation on the one hand and initialization (a.k.a. initialization) on the other. a.k.a. RAII (Resource Allocation Is Initialization
by zozbot123 8y ago
> Conflation of resource allocation on the one hand and initialization (a.k.a. initialization) on the other.
a.k.a. RAII (Resource Allocation Is Initialization). Which is very often what you want anyway.
- CoolGuySteve 8y agoJust because it has a name doesn’t make it a good idea necessarily. What one calls “initialization” someone else might call a “side effect”. In particular, sometimes you don’t want a bunch of allocations and locks firing on every function call and exit. C makes this behaviour explicit and C++ makes it implicit.
- bunderbunder 8y agoAs others have said, it depends on your context. If you need to be able to maintain tight control over resource usage, for example, RAII creates challenges. It can also be a bit of a chore to think about if you're doing interop with other languages. I've come to think of C++ as the tiktaalik of programming languages: It can live in two environments, and was an important evolutionary step in transitioning from one to the other. But, ultimately, it embodied so many design compromises that it was never going to be ideally suited to either of them.