Bjarne Stroustrup: Constructors, Destructors, and Resource Acquisition Is Initialization (RAII)

Bjarne Stroustrup explains why constructors and destructors are C++'s most important feature. They let you control when objects are born and die, giving you predictable performance without garbage collection. The pattern entered C++ in 1979.
Questions this video answers
In 1979, about the second week of his work on what was then called CVA classes.
Chapters
There's a lot of features that came in in C11. There's a lot of features at the birth of C that were amazing and ideas with concepts in 2020, what to you is the most just just to you personally beautiful or just do you sit back and think, wow, that's just nice and clean Feature of C. I have written two papers for the History of Programming Languages conference which basically ask me such questions and I'm writing a third one which I will deliver at the History of Programming Languages conference in London next year. So I've been thinking about that and there is one clear answer. Constructors and destructors. The way a constructor can establish the environment for the use of a type for an object and the destructor that cleans up any messes at the end of it. That is the key to C. That's why we don't have to use garbage collection. That's how we can get predictable performance. That's how you can get the minimal overhead in many, many cases and have really clean types. It's the idea of constructor destructor pairs. Sometimes it comes out under the name Resource acquisition is initialization, which is the idea that you grab resources in the constructor and release them in destructor. It's also the best example of why I shouldn't be in advertising. I get the best idea and I call it Resource acquisition. Is initialization not the greatest naming I've ever heard? So it's types, abstraction of types. You said I want to create my own types. So types is an essential part of C and making them efficient is the. Is the key part. And to you, the. This is almost getting philosophical, but the construction and the destruction, the creation of an instance of a type and the freeing of resources from that instance of a type is what defines the object is. That's almost like birth and death is what defines human life. Yeah, that's right. By the way, philosophy is important. You can't do good language design without philosophy because what you are determining is what people can express and how. This is very important. By the way, constructors, destructors came into C in 79 in about the second week of my work with what was then called CVA classes. It is a fundamental idea. Next comes the fact that you need to control copying because once you control, as you said, birth and death, you have to control taking copies, which is another way of creating an object. Finally, you have to be able to move things around so you get the move operations. That's the set of key operations. You can define on a C type. To you, those things are just a beautiful part of C that is at the core of it all. Yes?










