back to indexBjarne Stroustrup: Constructors, Destructors, and Resource Acquisition Is Initialization (RAII)
00:00:00.000 |
There's a lot of features that came in in C++11. 00:00:06.040 |
There's a lot of features at the birth of C++ that were amazing and ideas with concepts 00:00:14.560 |
What to you is the most, just to you personally, beautiful or just you sit back and think, 00:00:26.120 |
"Wow, that's just nice and clean feature of C++." 00:00:32.920 |
I have written two papers for the History of Programming Languages Conference, which 00:00:42.020 |
And I'm writing a third one, which I will deliver at the History of Programming Languages 00:00:51.880 |
And there is one clear answer, constructors and destructors. 00:00:56.560 |
The way a constructor can establish the environment for the use of a type for an object, and the 00:01:04.800 |
destructor that cleans up any messes at the end of it. 00:01:11.000 |
That's why we don't have to use garbage collection. 00:01:14.200 |
That's how we can get predictable performance. 00:01:17.840 |
That's how you can get the minimal overhead in many, many cases and have really clean 00:01:26.640 |
It's the idea of constructor-destructor pairs. 00:01:30.840 |
Sometimes it comes out under the name R-A-I-I. 00:01:36.080 |
Resource acquisition is initialization, which is the idea that you grab resources in the 00:01:44.720 |
That's also the best example of why I shouldn't be in advertising. 00:01:48.480 |
I get the best idea and I call it resource acquisition is initialization. 00:02:09.620 |
So types is an essential part of C++ and making them efficient is the key part. 00:02:18.120 |
And to you, this is almost getting philosophical, but the construction and the destruction, 00:02:25.000 |
the creation of an instance of a type and the freeing of resources from that instance 00:02:36.880 |
That's almost like birth and death is what defines human life. 00:02:46.120 |
You can't do good language design without philosophy because what you are determining 00:02:57.740 |
By the way, constructors-destructors came into C++ in '79, in about the second week 00:03:04.720 |
of my work with what was then called C++ classes. 00:03:11.380 |
Next comes the fact that you need to control copying because once you control, as you said, 00:03:17.240 |
birth and death, you have to control taking copies, which is another way of creating an 00:03:25.360 |
And finally, you have to be able to move things around. 00:03:31.300 |
And that's a set of key operations you can define on a C++ type. 00:03:37.920 |
And so to you, those things are just a beautiful part of C++ that is at the core of it all?