1 00:00:00,650 --> 00:00:04,110 So I said, okay. 2 00:00:18,910 --> 00:00:28,000 I'm going to tell you a little bit about C++. And most such talks either about what language is or how you use it. 3 00:00:29,050 --> 00:00:34,900 This I'm trying to make a talk about how the language became to be what it is and 4 00:00:34,900 --> 00:00:39,130 is the key evolution from the early days up till about three years from now. 5 00:00:39,910 --> 00:00:43,450 And if I get a bit boring, you can look at the pictures. 6 00:00:44,440 --> 00:00:48,310 Essentially all of the pictures have something or other to do with C++. 7 00:00:49,510 --> 00:00:55,540 Like, what do you think? Those turbines have been programmed in and so that's it. 8 00:00:55,750 --> 00:01:00,549 I am going to go a little bit into what is C++, his role in the world. 9 00:01:00,550 --> 00:01:07,030 What is what did I intended to be and what what what is it now? 10 00:01:07,390 --> 00:01:15,520 Then I'm going to give a code example. I really feel like a total fraud if I talk about programming and software development without showing code. 11 00:01:16,030 --> 00:01:24,780 I mean, if you see a presentation about software development without code, I start to worry and then I'm going to talk about the reason evolution. 12 00:01:24,790 --> 00:01:32,530 A lot of the talk has to do with what has happened in the last, uh, minus ten plus three years, something like that. 13 00:01:33,310 --> 00:01:40,180 And my, my thesis here is that the value of programming language is the quality of the applications. 14 00:01:40,510 --> 00:01:43,840 What matters is what interesting things you do with it. 15 00:01:44,140 --> 00:01:50,049 That is my measure of success, not the how clever code I can fit into it. 16 00:01:50,050 --> 00:02:00,340 You were column published format this this is this is very much a practical exercise trying to to do something good in the world. 17 00:02:00,340 --> 00:02:05,710 Of course, you don't control what people are using the language for and some of the things you might not like. 18 00:02:06,070 --> 00:02:10,750 But these are the things I consider somewhat cool. 19 00:02:11,200 --> 00:02:15,370 And I am not going to enter into language wars. 20 00:02:15,790 --> 00:02:19,720 I am I try not to be rude about C++ applications. 21 00:02:20,590 --> 00:02:28,720 So that said, you are not going to drag me into that and there's lots of interesting stuff here. 22 00:02:29,800 --> 00:02:38,590 So what I've been doing since my PhD days is distributed systems and I'm still very interested in that doing it. 23 00:02:38,860 --> 00:02:42,189 There is my one of my notions of a distributed system. 24 00:02:42,190 --> 00:02:48,009 It's a distributed system with wheels and a lot of C++ turns up in places where 25 00:02:48,010 --> 00:02:52,180 you would never think about it and you will never see it if it works right. 26 00:02:52,960 --> 00:02:56,950 It's if you notice, it's C++ is probably because something went wrong. 27 00:02:57,610 --> 00:03:01,600 The point here is that nobody understands all of this. 28 00:03:01,630 --> 00:03:10,000 Nobody can understand in any depth all the applications that I was just flicking through a few pictures of, neither do I. 29 00:03:10,450 --> 00:03:15,940 However, the purpose of the exercise, as far as I'm concerned, is to help people that are building these things. 30 00:03:16,300 --> 00:03:21,280 Therefore, if I build something that can only do what I can imagine, I failed. 31 00:03:22,030 --> 00:03:31,780 You have to do things I couldn't possibly imagine. The group here has more ideas, more needs than I could imagine, and that's part of the point. 32 00:03:32,380 --> 00:03:36,880 So what actually matters? The answer is lots of things. 33 00:03:37,780 --> 00:03:45,070 And one theme here is that we need stability and evolution. 34 00:03:45,220 --> 00:03:51,400 We need a language to evolve, our toolset to evolve so that it can handle new things. 35 00:03:51,400 --> 00:03:56,620 The world is changing. We're changing, the challenges are changing, and the language has to do it. 36 00:03:56,950 --> 00:04:02,380 On the other hand, you've always seen languages that are really cool for about five years. 37 00:04:02,830 --> 00:04:10,510 Then their design gets a promotion and it dies. We can't have that, not for things that lasts for decades. 38 00:04:11,050 --> 00:04:17,650 A lot of the things in my pictures have the interesting property that they were written ten, 15, 20 years ago. 39 00:04:17,860 --> 00:04:22,180 They are still being developed and changed. You have to handle that span. 40 00:04:22,510 --> 00:04:27,640 That's really hard and obviously there's enough in this kind of stuff to talk for days. 41 00:04:28,240 --> 00:04:35,650 I have one hour. I'd like to point out that the best being the best at one or two things is not sufficient. 42 00:04:36,310 --> 00:04:41,889 I mean, that's how you can write a really nice paper. I'm nothing against academic papers. 43 00:04:41,890 --> 00:04:47,740 I read a lot of them. I have written a fair number of them, but that is not the end product for tool. 44 00:04:47,740 --> 00:04:54,220 Building a tool is good enough if it is good enough for everything that somebody's using it. 45 00:04:55,360 --> 00:05:02,170 Needs. Now you have to remember that no language is good enough for everybody and for everything. 46 00:05:02,560 --> 00:05:06,670 But if you should use a chore, it should be good enough. 47 00:05:06,670 --> 00:05:12,010 At what? At every aspect of what you are doing, not just being the best at something. 48 00:05:12,640 --> 00:05:20,860 And so let's go back and see what the world was like when when I started photography was mostly black and white. 49 00:05:20,950 --> 00:05:24,940 Seems that is a large computer. 50 00:05:25,600 --> 00:05:37,420 It's a PDP 1170. It allows a programmer to have 250 K of memory and it runs with only almost a megahertz. 51 00:05:37,810 --> 00:05:44,740 Only almost. And this is Dennis Ritchie and Ken Thompson working on it. 52 00:05:45,040 --> 00:05:50,950 Notice the highly advanced IO system. That was what the world looked like. 53 00:05:51,070 --> 00:05:54,850 And there's lots of things we didn't have function prototypes. 54 00:05:55,330 --> 00:06:03,940 I hadn't invented them yet, so I didn't have it. And it was the state of the art in aesthetic development. 55 00:06:03,940 --> 00:06:11,960 Yes. Lots of languages has functions, document checking and conversion, but C did this all kinds of stuff. 56 00:06:11,980 --> 00:06:15,459 PDP levels were cool. 90/100. They didn't even have one. 57 00:06:15,460 --> 00:06:23,680 That's a teletype. One of the points is that everybody knew that object oriented was useless. 58 00:06:25,210 --> 00:06:31,240 This is almost right because 99% of people didn't know what object oriented was, 59 00:06:31,240 --> 00:06:35,170 never heard of it, and of the ones that knew about it, knew it wouldn't work. 60 00:06:35,680 --> 00:06:39,670 It was too slow to spatial purpose and too difficult for ordinary mortals to use. 61 00:06:41,050 --> 00:06:47,620 And I tried to convince somebody and says, If you want a virtual function, you haven't done your analysis right. 62 00:06:47,870 --> 00:06:51,400 I mean, you want to call a function. You don't know which one it is. 63 00:06:52,270 --> 00:06:56,740 It's absurd. So there were some obstacles to overcome. 64 00:06:57,310 --> 00:07:06,460 I point this out because in retrospect, a lot of this looks trivial and easy, so I probably won't convince you, but it wasn't easy. 65 00:07:07,240 --> 00:07:11,800 So here's sort of a history chart as it relates to C++. 66 00:07:12,550 --> 00:07:19,720 Here is a line of development where the purpose of the exercise is to extract every single byte. 67 00:07:19,720 --> 00:07:29,530 Every single cycle out of the machine starts with a simpler machine code, go through BGP on C and then to C++. 68 00:07:29,890 --> 00:07:34,930 And up here we have the great improvement in programming, the greatest in history, 69 00:07:35,230 --> 00:07:42,820 which is basically somebody figured out that we should have human oriented things, application specific. 70 00:07:43,760 --> 00:07:50,810 Concepts in a language so that we can talk about our programs in the vocabulary we use when we design things, 71 00:07:51,080 --> 00:07:54,350 as opposed to looking at the machine all the time. That's Fortran. 72 00:07:54,620 --> 00:07:58,750 And as soon as people had Fortran business people wanted one. 73 00:07:58,760 --> 00:08:00,739 They got COBOL and everybody wanted one. 74 00:08:00,740 --> 00:08:11,270 And very soon we had about 20 of them and had the net effect that everybody could write in a specific domain, much more pleasant than assembler. 75 00:08:11,930 --> 00:08:15,409 However, they couldn't talk to each other. The terminology was different. 76 00:08:15,410 --> 00:08:19,700 The data formats were different. They couldn't even exchange data. 77 00:08:20,000 --> 00:08:30,470 So Simula here came about together with object oriented programming as an attempt to say, Why put application specific? 78 00:08:31,540 --> 00:08:33,560 Concept into a programming language. 79 00:08:33,580 --> 00:08:41,650 Why don't we instead give the programmers the ability to design their own abstractions, their own concepts, their own types? 80 00:08:42,340 --> 00:08:44,530 And that's how we got object oriented programming. 81 00:08:44,800 --> 00:08:50,920 And if you write in any programming language that calls a Type A class, you can say thanks to a question. 82 00:08:50,920 --> 00:08:55,990 You go there because that's where it came from. Computer science was very new. 83 00:08:56,560 --> 00:08:59,800 He was trained as a mathematician. He knew what classes was. 84 00:09:00,040 --> 00:09:07,590 He did not know what types were. And so I needed something that could handle abstraction and could handle hardware. 85 00:09:07,600 --> 00:09:13,090 And that's why I built C++ by allowing abstraction mechanisms to be used there. 86 00:09:13,420 --> 00:09:16,090 And lots of interesting things happened after that. 87 00:09:17,530 --> 00:09:25,360 Now, C++ is, as far as I'm concerned there, so that I don't have to choose between elegance and efficiency. 88 00:09:26,550 --> 00:09:29,790 When I do things well, they are elegant and efficient. 89 00:09:30,330 --> 00:09:36,270 That is when you express things really well, really clear, really logically consistent. 90 00:09:37,050 --> 00:09:41,370 Hopefully the optimiser goes and generates a really good code. 91 00:09:41,700 --> 00:09:47,160 That's the idea. And sometimes we get it. Don't get it all the time and we can do even better. 92 00:09:47,280 --> 00:09:54,840 But that's the idea. And we do that by defining lightweight abstractions, not big, heavy, complicated abstractions. 93 00:09:54,940 --> 00:09:57,450 They are relatively easy, and you can do them in any language. 94 00:09:57,750 --> 00:10:04,530 But if you want a point and a matrix and a complex number, it gets really quite difficult. 95 00:10:04,740 --> 00:10:11,250 And that's where the challenges are. And so she has been developed as language for resource constrained applications. 96 00:10:11,970 --> 00:10:16,530 There's lots of applications that you saw on those pictures and lots of the stuff that I worked on. 97 00:10:17,430 --> 00:10:19,920 Well, starting in the eighties and still today, 98 00:10:20,280 --> 00:10:28,410 where you could do much better if you had twice as much memory or twice as many processors or twice as fast processors. 99 00:10:28,740 --> 00:10:38,550 But you don't. Those server farms cost 60 million USD, and if your code is half the speed of what it should be. 100 00:10:38,670 --> 00:10:44,730 You need to buy two and you have to power them up and run them and maintain them and all of this kind of stuff. 101 00:10:44,970 --> 00:10:50,490 So this is where resource constraints matters, and that means C++ is deep, 102 00:10:50,490 --> 00:11:00,450 deep in our software infrastructure because that's where you have the constraints of performance and reliability and all the other good stuff. 103 00:11:01,230 --> 00:11:06,690 And C++ offers a direct map to hardware and a zero warhead abstraction. 104 00:11:06,750 --> 00:11:13,410 Those are those two lines on the history chart. And again, no language is perfect for everything and everybody. 105 00:11:13,980 --> 00:11:17,700 And I don't know how many of you have have read the Dragon book. 106 00:11:18,030 --> 00:11:21,840 It's a classical textbook in about how to build compilers. 107 00:11:22,350 --> 00:11:30,240 It shows the knight armed with the weapons of computer science, defeating the dragon of complexity. 108 00:11:31,850 --> 00:11:36,770 Sometimes the dragon wins. We haven't reached perfection. 109 00:11:36,980 --> 00:11:41,570 We can do much better. So here's what I mean by a direct map to hardware. 110 00:11:41,990 --> 00:11:45,590 The primitive operations map to instructions on the set. 111 00:11:45,620 --> 00:11:49,420 If you add two integers, it's the integer edge operation. 112 00:11:49,460 --> 00:11:57,710 Seems simple, but a lot of languages don't do it. Memory is just a sequence of objects. 113 00:11:58,670 --> 00:12:04,850 You quite often bytes and you have addresses that can show which by the which object you are talking about. 114 00:12:05,210 --> 00:12:13,750 That's it. It's a brilliantly simple abstraction that any stretch you made you can compose object the simple concatenation. 115 00:12:13,760 --> 00:12:18,600 Like if you take some of the same type and put them next to each other, you get an array. 116 00:12:18,950 --> 00:12:25,220 If you put things that are different types together, you can get structs and classes and things like that. 117 00:12:25,610 --> 00:12:35,090 And if you need to refer to something that's elsewhere, you have pointers that are simply, simply machine addresses and sweet and sour sauce. 118 00:12:36,500 --> 00:12:41,230 So basically, this is the real secret of C in C++. 119 00:12:41,240 --> 00:12:44,720 It's really simple. It's really easy to map to the hardware. 120 00:12:45,050 --> 00:12:50,030 It's compact. It's efficient. Okay, so down by the hardware, 121 00:12:50,030 --> 00:12:59,450 life is actually rather unpleasant because there's not much help and you don't really want to work with bytes and and words and such all the time and, 122 00:12:59,720 --> 00:13:03,350 and raw pointers and such. So we want to abstract from it. 123 00:13:03,680 --> 00:13:12,980 And so the basic idea of C++ is that it should allow you to build your own types, and they should follow what I call the zero or head principle. 124 00:13:13,400 --> 00:13:16,590 What you don't use, you don't pay people and what you do use. 125 00:13:16,610 --> 00:13:18,410 You shouldn't be able to encode any better. 126 00:13:18,800 --> 00:13:29,810 So if I'm providing a notion of a class, you should not be able to hand code it with pointers and structs and stuff like that does anything better. 127 00:13:30,290 --> 00:13:36,130 And there's lots of examples here. And finally, sometimes we don't actually need to generate any code. 128 00:13:36,140 --> 00:13:40,430 We just compute the answer at compile time. That's getting more and more popular. 129 00:13:41,060 --> 00:13:48,280 So here it's abstractions all the way down. We start with our high level abstractions and they build on low level abstractions. 130 00:13:48,290 --> 00:13:52,910 They build on the language which builds on the on the basic machine model. 131 00:13:53,060 --> 00:14:02,630 And the machine model is also an abstraction. Of course, there is much more to the machine architecture than that. 132 00:14:03,590 --> 00:14:06,900 That's caches and all kinds of stuff like that. 133 00:14:06,920 --> 00:14:10,100 This is an abstraction. This is Dennis's abstraction. It's a good one. 134 00:14:10,100 --> 00:14:14,120 I borrowed it. And you go down, you get to the hardware. 135 00:14:14,270 --> 00:14:19,700 And what do you find? No. An entire machine does not execute 86 instructions directly. 136 00:14:19,880 --> 00:14:26,840 It translated six instructions into a much nicer instruction set, which it can optimise and execute better. 137 00:14:26,990 --> 00:14:34,360 It's abstractions all the way down into turtles, and you always have to abstract from concrete examples. 138 00:14:34,370 --> 00:14:38,510 There are people who think abstraction is another word for bloat. 139 00:14:40,130 --> 00:14:47,780 This is not the case. If you do it right, you abstract from concrete examples, maintaining performance all the way up. 140 00:14:48,260 --> 00:14:56,299 And you have to keep simple things simple. Because sometimes when you abstract things so that it can do everything, you can do nothing. 141 00:14:56,300 --> 00:15:01,760 Simply you want simple things to be simple. These are sort of design principles that I've worked with over the years. 142 00:15:02,270 --> 00:15:07,190 And then there's this question of naming How did C++ get to be core C++? 143 00:15:07,550 --> 00:15:13,490 Well, there wasn't a language here called CPU. It initially stood for Cambridge programming language, 144 00:15:13,490 --> 00:15:20,330 then they ran out of money and combined with Imperial and then was combined programming language. 145 00:15:20,540 --> 00:15:26,330 And then it was too complicated. They couldn't build it and it died, except they built a simple thing. 146 00:15:26,600 --> 00:15:30,890 And Richards built a similar thing called Basic Spiel we had at M.I.T. actually. 147 00:15:31,100 --> 00:15:38,090 And then it became B for a short while. And C was Dennis's work that made it efficient and better for poor hardware use. 148 00:15:38,390 --> 00:15:46,430 And then she ran classes, as it was called, for about three years till I was told I couldn't call it see the classes because 149 00:15:46,430 --> 00:15:50,360 some people were calling C old C and that was supposed to be rude to Dennis. 150 00:15:50,690 --> 00:15:55,840 I was not rude to Danish. I had lunch with him most days and never set up. 151 00:15:56,300 --> 00:16:01,520 We never had a hash word between us and then I tried to call it c, 152 00:16:01,700 --> 00:16:09,169 c c 84 that never flew because the people from the C committee came and said, Well, please don't do that, John. 153 00:16:09,170 --> 00:16:21,830 It would really be embarrassing if a superset or C 85, the standard C would be a a a subset of C 85. 154 00:16:22,550 --> 00:16:26,780 Anyway, they didn't finish till 89, but anyway, that was not so. 155 00:16:26,780 --> 00:16:32,770 I had a competition for calling it. Something and C++ one. 156 00:16:32,980 --> 00:16:37,840 As I said, we knew plus plus C was semantically better, but that was too much of a joke. 157 00:16:38,950 --> 00:16:43,360 So. What is straight you doing up there? 158 00:16:44,110 --> 00:16:52,060 The answer was he was the main designer of Kpl and it didn't matter Willow's Cambridge or combined because everybody knew it stood for Christopher. 159 00:16:54,010 --> 00:16:57,850 So that's. You still got it there? Uh oh. 160 00:16:57,850 --> 00:17:03,130 I should point out that's Maryhill Hill, where I worked and where I designed C++ right over there. 161 00:17:03,550 --> 00:17:10,540 And that's Cambridge part of it. So what features do C++ offer? 162 00:17:11,020 --> 00:17:17,050 Well, we had a competition a couple of years ago for what is your favourite C++ feature? 163 00:17:17,530 --> 00:17:23,290 And when Roger suggests that in Curly, we all backed off, that that can't be beat. 164 00:17:23,290 --> 00:17:32,770 That's it. That's where all the magic happens. So one of the things that distinguishes C++ over the years is this model. 165 00:17:32,920 --> 00:17:39,910 You make objects with constructors. And if you don't say anything else in a scope and the end of the scope, 166 00:17:40,090 --> 00:17:46,420 the destructor fires doing the magic, cleaning up the messes, closing up what should be closed up. 167 00:17:46,750 --> 00:17:52,420 That that's the really key. And I looked at my notes and it's a real call, C++. 168 00:17:52,420 --> 00:17:59,350 It came in in the first two weeks of development back in 79, together with classes, 169 00:17:59,350 --> 00:18:06,850 member functions, information, hiding function declarations and other stuff like that. 170 00:18:07,330 --> 00:18:11,290 And basically, that is the key to a lot of what we are doing today. 171 00:18:11,650 --> 00:18:16,570 The standard library uses it. Error handling is depending critically on it. 172 00:18:16,960 --> 00:18:21,730 So what is it? Here's a type A user defined type A class. 173 00:18:22,060 --> 00:18:25,660 It has two parts, the public interface and the implementation. 174 00:18:25,900 --> 00:18:31,150 So basically this is one level of abstraction and that is a low level of abstraction on which it is built. 175 00:18:31,480 --> 00:18:33,880 And you work that up and down all the way. 176 00:18:34,240 --> 00:18:43,300 And I have given it this an element type, and it is you can construct this one by a list of initialises of its element type. 177 00:18:43,690 --> 00:18:48,130 And here is the cleanup function. That's where you release the memory do so. 178 00:18:48,340 --> 00:18:56,170 Here we can use it. I take a vector of doubles with some well-known constants and I take a vector strings with some well-known language designers. 179 00:18:56,620 --> 00:19:00,160 I would like to point out I've been using this slide for years. 180 00:19:00,430 --> 00:19:05,730 I did not put it in to Greenshoe this this is this is this is the way I do it. 181 00:19:05,740 --> 00:19:13,720 And basically we get to the end, curly, here it goes and cleans up everything that was created by the objects in that scope. 182 00:19:14,320 --> 00:19:20,559 And that's a very powerful abstraction mechanism. So we use it for just about everything. 183 00:19:20,560 --> 00:19:29,320 In the C++ standard library, there's vectors, lists, maps, hash tables, strings and such. 184 00:19:29,320 --> 00:19:31,090 They, they are all working on this model. 185 00:19:31,480 --> 00:19:40,150 You acquire resources when you when you, when you create a variable and you release it again at the end of the scope. 186 00:19:40,600 --> 00:19:44,200 And this is these are things that we acquire. It's not just memory. 187 00:19:44,770 --> 00:19:51,790 There's things like thread handles, file handles, buffer capacities for for streams, locks. 188 00:19:51,910 --> 00:19:55,510 And when we have smart pointers, we do use counts and things like that. 189 00:19:55,960 --> 00:20:05,950 This means that if you can't just fire up a garbage collector and collect all the memory, not only would that give you longer resource retention, 190 00:20:06,400 --> 00:20:11,710 because instead of cleaning up the mess, you leave the mess for somebody else to clean up later. 191 00:20:11,980 --> 00:20:15,460 Therefore, the resource is held on for much longer. 192 00:20:15,610 --> 00:20:20,979 Some experiments shows on average twice anyway, and this works recursively. 193 00:20:20,980 --> 00:20:31,870 So if I have something like a catch it, which holds a five handle and a lock and such, and a vector of records that contains it all works recursively. 194 00:20:31,990 --> 00:20:37,960 It works all the way. Okay, so let's take a more concrete example. 195 00:20:38,290 --> 00:20:44,920 Semi concrete, that's a gadget I created with some initialise and I get a pointer out there. 196 00:20:45,220 --> 00:20:50,770 This is the way we wrote code in the in the eighties. 197 00:20:51,010 --> 00:20:54,040 This is the way they wrote code and Simula in the sixties. 198 00:20:54,040 --> 00:20:57,130 There's nothing new here and we've seen too much of it. 199 00:20:57,490 --> 00:21:01,450 But anyway, this is what we do. We don't actually know what this one does. 200 00:21:01,630 --> 00:21:08,950 It's constructor grabs all the resources necessary for working well and now it's ready to use. 201 00:21:08,950 --> 00:21:12,490 And we go down here and if this X is there, we throw something. 202 00:21:12,790 --> 00:21:19,900 If X is that we return. And when we finished we delete the the the object again. 203 00:21:20,200 --> 00:21:28,330 I mean we acquire using a new we delete it we release versus using delete. 204 00:21:28,690 --> 00:21:31,810 However, as you see, sometimes we don't get there. 205 00:21:32,320 --> 00:21:36,490 So people scream we want garbage collection because this is easy to forget. 206 00:21:36,490 --> 00:21:39,520 It's easy to get wrong is particularly if we. 207 00:21:39,910 --> 00:21:43,150 We don't get there. If we return, we don't get there. So there's leaks. 208 00:21:43,360 --> 00:21:49,419 And so it comes that you don't really want news sitting out there naked and you don't 209 00:21:49,420 --> 00:21:53,860 want the leaks being there naked because they correlate very strongly with bugs. 210 00:21:54,280 --> 00:22:01,810 So we want to get rid of it. There's an easy way of getting rid of it is that instead of having the gadget made by New, 211 00:22:02,170 --> 00:22:08,739 we have a function in the standard library called Make sure it makes an object of that type with that initialise and 212 00:22:08,740 --> 00:22:16,240 return a SharePoint to a SharePoint as a counter pointer when the last SharePoint as shown object is destroyed. 213 00:22:16,670 --> 00:22:28,600 The use count has gone to zero. It destroys an object it owned and therefore we will have to get it destroyed there, there and there. 214 00:22:29,050 --> 00:22:30,820 And the problem goes away. 215 00:22:31,900 --> 00:22:43,870 Except that now we have SharePoint us and we have use count and this violates the zero head principle because we have to access that use 216 00:22:43,870 --> 00:22:51,610 count updating and release it in a multi-threaded environment that is actually a costly operation because it has to be synchronised. 217 00:22:52,270 --> 00:22:56,770 And anyway, I, I don't want to create garbage. 218 00:22:56,920 --> 00:23:00,340 I can't see any garbage here that needs to be collected. 219 00:23:00,610 --> 00:23:04,180 I can't see anything there. Require use part. I have one pointer. 220 00:23:05,260 --> 00:23:08,860 And it goes away. Why do I have to count? 221 00:23:09,610 --> 00:23:13,230 Zero, one, zero? No, we can do better. 222 00:23:13,500 --> 00:23:15,420 Actually, the simpler code is there. 223 00:23:16,140 --> 00:23:22,650 You just take a local variable, control it and you use it, and the destructor would be called there, the end there. 224 00:23:22,860 --> 00:23:28,440 Because when you go out of scope, the destructor is caught. Problem solved and the code is shorter. 225 00:23:28,800 --> 00:23:38,970 And so don't use new in general code because they belong in resource management code. 226 00:23:39,510 --> 00:23:44,880 So if I see a delete in your code, I assume there's a bug that you have too few too many deletes. 227 00:23:45,060 --> 00:23:49,180 And if I see a new I know you need a delete somewhere, so I assume there's a bug in your code. 228 00:23:50,340 --> 00:23:55,739 So this is much simpler and if you really need pointers that needs to be counted. 229 00:23:55,740 --> 00:24:01,170 You don't know about ownership. Yeah, SharePoint is there. It's actually quite useful, but people all use it. 230 00:24:01,680 --> 00:24:06,660 So this leaves us with one problem that is quite often we make a big object, 231 00:24:06,900 --> 00:24:13,530 so lots of data and then we wanted to get out of the function that did it, get back to whoever requested it. 232 00:24:13,950 --> 00:24:19,680 And this is what people use pointers for and they use free store, also known as dynamic memory or heap. 233 00:24:20,130 --> 00:24:24,360 They used to that and then they send a pointer back and they'll have all the problems back again. 234 00:24:24,870 --> 00:24:29,250 So we need to avoid that. So here I make the gadget from here, return it. 235 00:24:29,850 --> 00:24:33,540 And conventionally when we churn something, that's a copy. 236 00:24:34,230 --> 00:24:41,640 So basically here I call F and here we copy the and the G out to g g. 237 00:24:42,030 --> 00:24:45,870 Now, I must point out that only a computer scientist could have thought of that. 238 00:24:46,530 --> 00:24:51,419 So to get this one from here to there, you make a copy. 239 00:24:51,420 --> 00:24:56,670 Over the end, you destroy your original. No baby. 240 00:24:56,850 --> 00:24:59,880 About 4 to 6 months old. No. Here it is. 241 00:24:59,910 --> 00:25:02,970 Now it's over there. Now it's back again. They can figure it out. 242 00:25:03,390 --> 00:25:07,740 So we just have to make sure that that's what we do. So here is G. 243 00:25:07,770 --> 00:25:14,010 It's a gadget. And if it's a big thing, like a matrix, a vector, a collection of stuff, 244 00:25:14,490 --> 00:25:19,780 if the stuff will be over here somewhere on the on the free store and this is a handle to it. 245 00:25:20,040 --> 00:25:25,920 So all we need to do is to copy the handle into g, g and the handle is this more? 246 00:25:26,580 --> 00:25:30,780 If this was a matrix, it would probably be two words. If it's a vector, it's three words. 247 00:25:31,440 --> 00:25:39,330 And then we cut the connection to the first gadget so the destructor doesn't get to throw away the good stuff and problem solved. 248 00:25:39,780 --> 00:25:47,370 And so the cost of getting a megabyte of stuff out if you do it like this is, well, 249 00:25:47,370 --> 00:25:57,390 2 to 4 memory assignments and now you no longer have to worry about pointers and memory management or share pointers and all of this stuff. 250 00:25:57,420 --> 00:26:03,300 This completes the control of the lifecycle of, of, of, of objects. 251 00:26:03,600 --> 00:26:12,660 Now, some of us have been doing this since the nineties, but it's only became systematic and guaranteed that it could be done in. 252 00:26:13,710 --> 00:26:24,210 The and C++ 11. This is the handiwork of a guy called Howard Hint that found out how to to formalise that so that's easily done now. 253 00:26:25,140 --> 00:26:33,060 Also, I'd like to talk about evolution to point out that I have never claimed C++ is an object oriented language. 254 00:26:33,360 --> 00:26:39,240 It never was just an object oriented language is never meant to be just an object oriented language. 255 00:26:39,870 --> 00:26:43,680 I don't think everything should be in class hierarchies or any of that stuff. 256 00:26:44,220 --> 00:26:50,520 So she prefers not object oriented, is just object oriented for any definition of object oriented. 257 00:26:51,810 --> 00:26:57,750 For starters, we need to deal with this direct mapping to hardware when hardware tends to be messy. 258 00:26:57,750 --> 00:27:02,280 So we have to do things that that doesn't behave like objects in a real way. 259 00:27:02,550 --> 00:27:11,070 They actually real world objects. And you have to obey their curious and somewhat perverse semantics. 260 00:27:11,970 --> 00:27:16,230 So we deal with this. Furthermore, we want value semantics for some things. 261 00:27:16,650 --> 00:27:23,640 So A, B, A becomes B means that they have the same value and modification of the one doesn't fix the other. 262 00:27:24,000 --> 00:27:28,920 This is what we do for integers, for complex numbers, for points, for vectors, etc. 263 00:27:29,310 --> 00:27:35,520 So that's that, that's that model has always been in C++ and it's one of the things we do. 264 00:27:35,910 --> 00:27:39,810 Also, I want to say square root of two, not two dot squared. 265 00:27:41,310 --> 00:27:45,450 I really think this is the nicest notation. This is the nicest notation and such. 266 00:27:45,660 --> 00:27:49,469 And I don't want to have two versions of a of things. 267 00:27:49,470 --> 00:27:54,390 If I, if I add a floating point number to an integer. 268 00:27:54,660 --> 00:27:59,069 I don't want the integer class to have something that takes floating point numbers 269 00:27:59,070 --> 00:28:02,100 and the floating point number in class takes something that takes integers. 270 00:28:02,400 --> 00:28:13,650 I want the old fashioned 300 years old notations that furthermore, generic programming was always part of the C++ plan. 271 00:28:13,950 --> 00:28:19,439 So that's doesn't fit with the object oriented thing. 272 00:28:19,440 --> 00:28:25,710 So these days, the control of C++ is by an ISO standard committee. 273 00:28:26,310 --> 00:28:32,820 And the way that happened was that representatives from HP and Sun turned up 274 00:28:32,820 --> 00:28:39,300 in my office and explained to me that I wanted to standardise C++ with ISO. 275 00:28:39,840 --> 00:28:42,989 And I said, Well, it's not ready, it's not finished, it's through a project. 276 00:28:42,990 --> 00:28:46,740 And they sort of twisted my arm out and in the end I said yes. 277 00:28:47,220 --> 00:28:57,360 The argument was that you could not have a language, major language, supported by controlled by a single company. 278 00:28:57,600 --> 00:29:00,810 Everybody believed that in those days it has been proven untrue. 279 00:29:01,350 --> 00:29:09,840 People are using Java and C-sharp, even though they are owned and operated by an individual company that might be your competitor. 280 00:29:10,230 --> 00:29:15,900 Anyway, at the time, nobody believes that could be done. They had not thought about the advertising campaigns that could do it. 281 00:29:16,890 --> 00:29:28,530 And the other argument was rather blunt Well, we will not trust you as your employer, and we will, of course, trust you. 282 00:29:29,800 --> 00:29:33,940 But you could get run over by a bus. End of quote. 283 00:29:34,780 --> 00:29:44,200 So I agree to standardisation. There's many kinds of standardisation and the ISO standardisation here is sort of the gold standard of standardisation. 284 00:29:44,440 --> 00:29:47,200 It's thorough, it's open, and they have some rules. 285 00:29:47,500 --> 00:29:53,800 And so we get long term stability, which is a feature, an important feature to many of the major users. 286 00:29:54,250 --> 00:30:03,220 It's vendor neutral. It's really hard to sort of jargon or the C++ definition so that it favours my company rather than yours and such. 287 00:30:03,790 --> 00:30:06,940 And danger is designed by a committee is horrible. 288 00:30:07,690 --> 00:30:15,430 Stagnation could happen if people decided not to do major things because they couldn't agree on which major things to do. 289 00:30:15,700 --> 00:30:18,000 There is divergent direction of design. 290 00:30:18,010 --> 00:30:25,570 If you get sufficient number of people, they can't agree on anything and they have a tendency of or elaborating any individual feature. 291 00:30:25,810 --> 00:30:29,950 You can see that in C++ in places. I'm not going to go into detail. 292 00:30:30,190 --> 00:30:36,399 I'm just going to show you the picture of the committee. So this is what it looked like. 293 00:30:36,400 --> 00:30:42,550 Then it became set. Then it became that. And this was earlier this year. 294 00:30:44,150 --> 00:30:47,570 How do you get that group of people to agree of anything? 295 00:30:48,290 --> 00:30:54,500 They come from different countries. Different industries, have different philosophies, have different education. 296 00:30:54,770 --> 00:31:02,420 This is really, really hard. And I, I reckon this is a picture of my major problem with C++ today. 297 00:31:02,810 --> 00:31:06,390 It is amazing that we have succeeded as far as we do. 298 00:31:06,800 --> 00:31:16,490 But let's see. I'm going to talk the rest of time how we got from well about there till 20 years from now to three years from now. 299 00:31:16,880 --> 00:31:20,030 So that's evolution. We got a new standard in 11. 300 00:31:20,060 --> 00:31:28,000 The first one was in 98, then 14 and 17 C++ level was a major improvement. 301 00:31:28,010 --> 00:31:31,760 This was what we had learnt over the previous decade and a bit. 302 00:31:32,210 --> 00:31:38,990 Standards usually come every ten years. We actually took 13, which was one of the reasons we decided we can't keep on doing this. 303 00:31:39,380 --> 00:31:47,600 So we decided we were going to go on a three year cycle and actually deliver what we had to deliver. 304 00:31:48,050 --> 00:31:51,470 There's lots of new features in 11, lots of simplification. 305 00:31:51,470 --> 00:31:57,440 One of the ways I'm working is that there's a language we can't take things away because of stability. 306 00:31:57,590 --> 00:31:59,630 How can you make it simpler to use? 307 00:31:59,870 --> 00:32:09,290 And the answer is have features that are simpler to use than the general ones and then have rules for how to use them. 308 00:32:09,290 --> 00:32:13,549 Well, now people say, why don't you just throw away the old stuff? 309 00:32:13,550 --> 00:32:17,600 Well, half of the pictures I had in the first two slides were break. 310 00:32:17,870 --> 00:32:23,450 And people everybody wants two more features. And by the way, the language is too big. 311 00:32:23,900 --> 00:32:27,170 You should make it smaller and don't break my code. 312 00:32:28,400 --> 00:32:36,470 These are the sort of the hard constraints on evolution and we have technical specifications and such. 313 00:32:36,800 --> 00:32:45,140 Now we have three major implementation implementers of C++ playing Jesus, C and Microsoft. 314 00:32:45,560 --> 00:32:51,830 And by the way, they shipped essentially all of C++ 17 this year. 315 00:32:53,000 --> 00:32:57,140 And the standard hasn't been signed off in Geneva yet. 316 00:32:57,620 --> 00:33:02,000 The technical guys have done it and the technical guys have delivered the compilers. 317 00:33:02,300 --> 00:33:06,560 A lot of you will be using them already. We are delivering on time. 318 00:33:06,650 --> 00:33:13,370 This is spectacular. I mean, remember, we deliver on time. 319 00:33:13,520 --> 00:33:19,010 Not as much as I would like, but we delivered. So C++, 11, ten years of experience. 320 00:33:19,130 --> 00:33:25,970 Long list. You can look up the list. Wikipedia has some CGP references, lots of places. 321 00:33:25,970 --> 00:33:31,250 I am not going to go into details. Going through the slide in any detail will take a day. 322 00:33:31,370 --> 00:33:37,010 So we're not going to do that. I'm just going to show one example here of C++ 11. 323 00:33:37,430 --> 00:33:44,520 So here I'm going to say the old problem in a container C I want to find all the elements that has the value. 324 00:33:44,520 --> 00:33:50,780 V And what I'm going to do is I'm going to return a point of each of those elements. 325 00:33:51,770 --> 00:33:56,630 And let's see an example here we have a string. A string is container of characters. 326 00:33:56,960 --> 00:34:05,840 Mary had a little lamb here. And so for each pointer that comes out of find our as a result by giving it M and looking for the A's, 327 00:34:06,230 --> 00:34:11,240 I'm going to see if the pointer really points to A if it doesn't do something seriously wrong. 328 00:34:12,860 --> 00:34:17,780 Okay. So, so in other words, I want this to test whether that wasn't me. 329 00:34:17,780 --> 00:34:27,310 That was me. That was me and that was me. The way we do it is we start a vector of pointers to elements. 330 00:34:27,330 --> 00:34:37,570 In this case, the value type of C is character char and for each X in C sees the values, right? 331 00:34:37,590 --> 00:34:44,310 If it is, push the pointer to the end of the result vector and return the vector. 332 00:34:44,730 --> 00:34:53,280 Now, if this had been a C++ 98 program, we would have had a serious performance bug there because I mean, 333 00:34:53,280 --> 00:34:57,750 a vector for elements is not that expensive to to pass. 334 00:34:58,110 --> 00:35:06,960 However, I might have given it a megabyte of data and returned a million pointers and even modern hardware can feel copying a million pointers. 335 00:35:07,710 --> 00:35:13,080 However, modern vectors do not copy. 336 00:35:13,080 --> 00:35:22,290 They move. So that is dirt cheap. So the difference between C++ 11 and C++ 98, here is what you don't see. 337 00:35:23,630 --> 00:35:26,959 You don't see any pointers. You don't see any locations. 338 00:35:26,960 --> 00:35:30,410 You don't see any range checks. It's all gone away. 339 00:35:30,800 --> 00:35:34,520 It's done implicitly in places, and it's done efficiently. 340 00:35:35,180 --> 00:35:39,620 So that's what's different. So for 14, we finished 11. 341 00:35:40,070 --> 00:35:47,330 So the point here is that when you have a large project before the end of the project, before the shipping date, you have a feature freeze. 342 00:35:48,110 --> 00:35:52,760 And while the feature freeze happens, you learn things and you can't do anything about it. 343 00:35:54,030 --> 00:35:58,350 So for us, the end of the feature freeze is about a year before you ship the standards. 344 00:35:59,280 --> 00:36:05,160 After having a major release, you start using it and you learn things you hadn't guessed. 345 00:36:06,280 --> 00:36:12,450 You do. And so the idea is after three years we have had the feature freeze. 346 00:36:12,460 --> 00:36:20,920 We have learned what the effect of the the use of the features are, and we can fix it in time before the next feature each. 347 00:36:21,280 --> 00:36:25,320 And that's how we got C++ 14. It completes 11. 348 00:36:25,330 --> 00:36:28,720 That was all planned and it has lots of little things. 349 00:36:29,980 --> 00:36:38,530 There's this year, for instance, the graphical people really wanted binary constants, so we gave them binary constants. 350 00:36:38,960 --> 00:36:43,210 The OBI means it's a, it's a bit pattern. 351 00:36:43,780 --> 00:36:47,200 Then we found that people can't read this stuff and you see what that is. 352 00:36:48,070 --> 00:36:54,340 Okay. Then we gave people digit separators which are just for the humans reading the code. 353 00:36:55,090 --> 00:37:00,340 We're always interested in things that simplify things by making bugs more, less likely. 354 00:37:00,580 --> 00:37:06,400 And that's what this does. Lots of things here. Remember, we are still maintaining compatibility and stability. 355 00:37:06,670 --> 00:37:10,030 Yes, we would like to get rid of some of the old crud, but we can't. 356 00:37:10,090 --> 00:37:22,630 We've tried. So one of the things we've been doing in the Lake Framework, we had a lot of requests for being able to do more at compile time. 357 00:37:23,410 --> 00:37:27,729 So a lot of people do the following. 358 00:37:27,730 --> 00:37:30,220 They have some code and they need a value in there. 359 00:37:30,520 --> 00:37:37,150 So they go to a tool to pat on the side and they calculate it, or they use the calculator and they get a value and they put it into their code. 360 00:37:38,710 --> 00:37:44,560 Then you wait a couple of years and it's now the wrong value and you have a magic cast in your code and you have bugs. 361 00:37:45,010 --> 00:37:50,500 So we had requests potentially from the embedded systems industry for doing better things at compile time. 362 00:37:50,530 --> 00:37:56,170 They also sometimes want to put constants into run, and C++ wasn't good enough for that. 363 00:37:56,650 --> 00:38:01,390 Actually, I think it was, but they didn't agree. So here is an example. 364 00:38:02,020 --> 00:38:10,720 Somebody in the Japanese embedded embedded systems industry wanted an integer square root function to be executed at compile time. 365 00:38:11,140 --> 00:38:17,830 So when we do that, we say that we want to have it so that it can be calculated at compile time. 366 00:38:18,040 --> 00:38:23,880 Then we write the simplest algorithm we can find. This will be executed at compile time. 367 00:38:23,890 --> 00:38:27,820 The compiler executes it to be able to do this trick. 368 00:38:28,240 --> 00:38:36,640 The function has to be pure in the sense that it cannot have side effects and it cannot operate on any data that is in its arguments. 369 00:38:37,000 --> 00:38:41,540 If somebody likes nice mathematical functions, just just require their context. 370 00:38:41,570 --> 00:38:49,630 But that takes care of that problem. Furthermore, it allows the compiler to squirrel away the information necessary to do this. 371 00:38:50,170 --> 00:38:55,400 And if it did, if for every function you couldn't compile a really big program. 372 00:38:55,420 --> 00:39:02,110 So it's important that we have to say it. So we can now take the square root of nine and take it square with a one, two, three, four. 373 00:39:03,040 --> 00:39:06,159 And we don't have to use a do pattern. 374 00:39:06,160 --> 00:39:14,440 We don't have to do strange things with macros to do it. Now C++ supposed to do the basic stuff and then to handle abstractions. 375 00:39:14,770 --> 00:39:19,420 So let's see, we can do compiler time abstractions. Here's a little abstraction. 376 00:39:19,450 --> 00:39:22,690 It's a weekday of June 21st, 2016. 377 00:39:23,290 --> 00:39:26,290 This is an example of use of my favourite data library. 378 00:39:27,250 --> 00:39:30,790 This is is very nice. And it writes Tuesday. 379 00:39:31,330 --> 00:39:39,010 We can do that at compile time. Let's take a static assert, which is an assert that is evaluated at compile time to see if it works. 380 00:39:39,340 --> 00:39:44,920 So I'm saying that the weekday of June, the 21st, 2016 is a Tuesday. 381 00:39:46,010 --> 00:39:49,340 And it is. So this assertion does not fire. 382 00:39:50,150 --> 00:39:59,150 But if if I had been wrong, it would have given me a compile time era so we can actually do nontrivial computations at compile time. 383 00:39:59,180 --> 00:40:02,970 By the way, this library is more efficient than anything else you've done for data. 384 00:40:03,000 --> 00:40:07,250 So it's not this has not become elegant by being inefficient. 385 00:40:08,300 --> 00:40:16,820 So 17 should have been a major release. The idea was to pick up the intel idea of tick tock, tick tock, major release minorities made enemies. 386 00:40:17,180 --> 00:40:30,350 And C++ isn't 17 isn't. So if you hear me grumbling about the standards committee and slow rate of evolution of C++ and the many little features. 387 00:40:30,620 --> 00:40:33,830 This is what I mean. This should have been great. It's only okay. 388 00:40:34,850 --> 00:40:37,940 That is a little bit for everybody. 389 00:40:38,240 --> 00:40:42,740 I think everybody will find something they like. The problem is that there are. 390 00:40:45,470 --> 00:40:51,890 Maybe 80 different features. And if you like two of them, you still might have to understand the other. 391 00:40:52,070 --> 00:40:52,820 The rest of them. 392 00:40:53,150 --> 00:41:03,020 There's a nice parallelism library that's a variable type that's useful, some way of dealing with with with marginal return values and such. 393 00:41:03,380 --> 00:41:08,570 This this is good. This good. But it's not great. So let's see, where do we go from here? 394 00:41:09,380 --> 00:41:12,650 And we need a guiding philosophy for kind of this. 395 00:41:12,650 --> 00:41:15,790 We can't just say, is this feature good? 396 00:41:15,800 --> 00:41:20,210 Let's take it. Is this feature good? No, let's not take it. What are the criteria? 397 00:41:20,390 --> 00:41:23,210 What are the direction for where we are going? 398 00:41:23,480 --> 00:41:31,190 So basically my aims include complete type and resource safety as fast or faster than anything else, good on modern hardware, 399 00:41:31,400 --> 00:41:39,890 whatever modern hardware is going to become, and significantly faster compilation even though we are doing better checking. 400 00:41:40,490 --> 00:41:46,970 I don't think that's a modesty it and basically dream no little dreams. 401 00:41:47,060 --> 00:41:50,450 That's his slogan. And the best is the enemy of good. 402 00:41:50,480 --> 00:41:54,379 That's his slogan. I can't just dream. We're going to build something. 403 00:41:54,380 --> 00:42:01,550 It's going to be useful. I want this to be useful in 2020 and I want the prototypes to be usable next year. 404 00:42:03,410 --> 00:42:10,960 So we're going to do that. That's an engineer, right? So make C++ a much better tool for building demanding applications. 405 00:42:10,970 --> 00:42:14,930 That is the ultimate aim. And these are the sort of more specific aims. 406 00:42:15,200 --> 00:42:19,670 The challenge is I try to set the committee with the science. 407 00:42:20,030 --> 00:42:24,560 So my philosophy is a lot of what philosophy philosophers are anyway. 408 00:42:25,280 --> 00:42:31,460 So it is actually the only way of maintaining our direction and to have a coherent language. 409 00:42:31,610 --> 00:42:38,120 This is absolutely essential and it's more a language is more than a collection of features and individual 410 00:42:38,120 --> 00:42:44,300 feature can be great and just be a distraction in the context of a tape system and all the features. 411 00:42:44,330 --> 00:42:54,049 We must do better. We must have a balance of features and basically we don't want to have a habit and the design rules are mostly non-technical, 412 00:42:54,050 --> 00:42:56,330 and this is where it's hard to get through to the geeks. 413 00:42:57,800 --> 00:43:04,580 I actually wrote up some design criteria in the early days, and here's from a book I wrote about it The Design Evolution of C++. 414 00:43:04,850 --> 00:43:08,570 If you want to know about the early evolution of C++, you can read that book. 415 00:43:08,960 --> 00:43:17,540 And I wrote two papers for the History of Programming Languages Conference, which you'll find on my publication page that also describes evolution. 416 00:43:17,540 --> 00:43:22,700 It's all of these features I'm skipping over fast here because I only got an hour, but basically. 417 00:43:24,210 --> 00:43:32,850 Drive by real problems. I think theory is great for solving a problem once you have decided that it needs to be solved. 418 00:43:33,180 --> 00:43:41,580 I think theory is a lousy guide to what should be done and so don't have a stripe quest for perfection. 419 00:43:41,760 --> 00:43:48,450 If I can come up with a 99% solution, I'm not going to wait two years, three years, a decade for the last percent. 420 00:43:50,190 --> 00:43:54,270 And so there's things like this. You can read this for details. 421 00:43:54,510 --> 00:43:59,610 And I'd like to point out two of the things documented in 94. 422 00:43:59,610 --> 00:44:09,480 And actually, you could probably document them for for AG for all before no implicit violation of aesthetic type system. 423 00:44:10,050 --> 00:44:15,150 Now, this surprises people who I used to see and such and even parts of C++. 424 00:44:15,570 --> 00:44:18,660 But there's a difference between ideals and what you can get. 425 00:44:20,620 --> 00:44:26,590 I'm going to get this one sooner or later, but I haven't got to get any straight, she said. 426 00:44:26,620 --> 00:44:33,760 C++ is a strongly type programming language with weak enforcement very weak. 427 00:44:34,090 --> 00:44:40,390 But the underlying system is the same, except possibly for some conversions that go both ways. 428 00:44:40,990 --> 00:44:44,620 And anyway, I really want to eliminate the pre-processor. 429 00:44:45,040 --> 00:44:53,500 So still trying to do that is really hard. There's people got a million lines of code and says, You're telling me to get rid of the macros? 430 00:44:54,100 --> 00:44:57,670 Yeah, I'm telling you to get rid of the macros. And they, they, they, they laugh. 431 00:44:58,240 --> 00:45:05,980 But I actually think we're going to get rid of the macros in something like the Windows kernel. 432 00:45:06,460 --> 00:45:11,290 It's probably the worst macro [INAUDIBLE] on earth and that is why they have decided they 433 00:45:11,290 --> 00:45:16,090 actually agree with me because that [INAUDIBLE] is what they have been living in for a while. 434 00:45:16,240 --> 00:45:20,260 We are going to make progress. But remember this was early things. We are still working on it. 435 00:45:21,430 --> 00:45:24,490 So what do we want? I want a major release in 20. 436 00:45:24,580 --> 00:45:28,040 C++ 20. I want my definition of major. 437 00:45:28,060 --> 00:45:33,640 Is it something that changes the way you think about programming, the way you think about building systems? 438 00:45:33,880 --> 00:45:37,420 That's the definition of major. Minor is everything else. 439 00:45:37,990 --> 00:45:44,650 And what can we get? I like science fiction, but I don't like to talk science fiction. 440 00:45:44,830 --> 00:45:50,890 Everything on this slide actually has been implemented somewhere. 441 00:45:51,590 --> 00:45:57,430 So it's all very mired science fiction. And by the way, that is a show of slides. 442 00:45:57,910 --> 00:46:03,790 I really was very I thought it was very cool when I learned that Douglas Adams were programming in C++. 443 00:46:05,110 --> 00:46:08,740 And so this this this this video game was written in C++. 444 00:46:09,640 --> 00:46:14,230 So I want concepts, which basically is constraint generics. 445 00:46:14,590 --> 00:46:21,490 I want modules faster and more hygienic compilations, code change contract. 446 00:46:22,090 --> 00:46:32,920 I didn't know if, but when I wrote the slide, but last week I was told that the implementation has started in a university in Spain. 447 00:46:33,310 --> 00:46:40,870 Static reflection there's a problem. We have three designs, three with implementations. 448 00:46:41,080 --> 00:46:44,080 And now you have to have the community to decide which one to have. 449 00:46:44,710 --> 00:46:49,300 And I really, really want them not to have the union of those three designs. 450 00:46:50,320 --> 00:46:53,480 So that's that's what that question mark was for networking. 451 00:46:53,500 --> 00:47:02,280 We have a really nice networking library close to optimal in many ways in widespread production use, better parallel algorithms, better futures. 452 00:47:02,290 --> 00:47:07,989 We have the model of promises and futures for for sending information from 453 00:47:07,990 --> 00:47:13,120 one thread to another without having explicit locking and all of that stuff. 454 00:47:13,870 --> 00:47:18,790 We have it and it should be much better because there are some design errors in the C++ 11 455 00:47:18,790 --> 00:47:25,930 design and I want a new standard library with the concepts here so that we get proper teaching. 456 00:47:26,650 --> 00:47:27,550 Let's see how we do it. 457 00:47:30,140 --> 00:47:39,590 If you go back and look at my very early papers from 81 or thereabouts, you'll see I want an object oriented programming as pioneered by Simula, 458 00:47:39,830 --> 00:47:46,790 and I want that generic programming because basically I wanted a vector of cheese, which was something I could specify. 459 00:47:48,170 --> 00:47:54,730 As a parameter. And once you have vectors of cheese, you want a sort of cheese. 460 00:47:55,600 --> 00:48:02,710 What sort of victim of cheese? Where you have parameters for data structures, you have parameters for algorithms, for functions you need both. 461 00:48:03,250 --> 00:48:08,020 Okay. So I conjectured that you could use macros for that. 462 00:48:08,620 --> 00:48:11,690 That did not scale. Macros for generics. 463 00:48:12,190 --> 00:48:17,560 It works for about two people and not much more, and it's one maintainable. 464 00:48:18,190 --> 00:48:21,400 So in 87 I made a design of templates. 465 00:48:21,610 --> 00:48:24,880 I wanted extremely general and flexible. I always want that. 466 00:48:25,270 --> 00:48:27,760 I want zero overhead. I always want that. 467 00:48:28,120 --> 00:48:36,850 So basically, I wanted something that could do more than I imagined and could compete with crazy and other basic facilities there. 468 00:48:37,090 --> 00:48:43,660 And of course, I wanted well defined specify well specified interfaces because that's good and that's what we always want. 469 00:48:44,380 --> 00:48:48,100 And two out of three ain't bad. I could not do that. 470 00:48:49,090 --> 00:48:52,990 I don't think anybody in the Middle Ages could do all three. 471 00:48:54,070 --> 00:48:58,630 If you look at all the languages that has things like that, they don't have all three. 472 00:48:59,020 --> 00:49:04,360 So we can now do it. The way we do it is let's see. 473 00:49:05,140 --> 00:49:14,200 The problem was that we got compile time duck typing and it gets very, very complicated and horrendous error messages you get wrong. 474 00:49:14,620 --> 00:49:20,020 And it was very, very successful because of its nice features, flexibility, performance, etc. 475 00:49:20,440 --> 00:49:29,169 We are trying to attract address this complexity by providing context for functions, functions that can be evaluated a compiler time. 476 00:49:29,170 --> 00:49:31,930 So we do made a programming that is not to implement a programming. 477 00:49:32,170 --> 00:49:38,950 If the result of a compile time computation is a value like seven, you want to call a function to get it. 478 00:49:40,180 --> 00:49:46,480 And we want to specify interfaces. So here is an example of something using concept. 479 00:49:46,870 --> 00:49:50,349 I want to sort something and I want to sort anything that's sortable this there's a 480 00:49:50,350 --> 00:49:54,970 definition of what sortable somewhere you can look it up in the menu in the standard. 481 00:49:55,270 --> 00:49:58,450 It's something that has is a sequence with a beginning and the end. 482 00:49:58,990 --> 00:50:02,020 And it has elements. It has a lesson operator. 483 00:50:02,590 --> 00:50:05,590 And it has random access to the elements. 484 00:50:05,770 --> 00:50:11,860 That's it. So anyway, if I have one of those, I can sort it as it happens in the standard. 485 00:50:12,130 --> 00:50:17,780 You can't sort a list this way because the list doesn't have random access to which elements. 486 00:50:18,670 --> 00:50:25,240 So the way you do it is you just copy the list into a vector sorted and copy it back again. 487 00:50:25,450 --> 00:50:31,150 That's usually the most efficient way of, of, of, of doing a sort of a list. 488 00:50:31,990 --> 00:50:36,069 Now I can then say sort of actor and it says those make time. 489 00:50:36,070 --> 00:50:39,460 All the properties required for should be sortable. 490 00:50:39,940 --> 00:50:43,120 Yep. So we can call it. We can sort the list. 491 00:50:43,510 --> 00:50:48,370 Does the list have all the properties that is required to be sortable? 492 00:50:48,400 --> 00:50:51,879 No. Let's try this one. And the answer is yes. 493 00:50:51,880 --> 00:50:57,850 And we just do it. And notice I am not saying that a sequence is less than sortable or something like that. 494 00:50:58,270 --> 00:51:03,430 I'm just trying to see what works. And this is very simple over all loading rule. 495 00:51:03,760 --> 00:51:07,630 If you match one thing, that's it. If you matched two things. 496 00:51:07,840 --> 00:51:12,460 If the one is a subset of the other, you pick the largest end of rules. 497 00:51:13,150 --> 00:51:16,990 So that works nicely, and you can specify your requirements like this. 498 00:51:18,010 --> 00:51:24,549 A sequence. It requires that the type has an iterator that has a beginning and the end they have an iterator and 499 00:51:24,550 --> 00:51:31,240 those generators are actually iterator is not just called generators in the story and concepts. 500 00:51:31,270 --> 00:51:36,190 Sortable means that it's a sequence with random access with the order of value type. 501 00:51:36,790 --> 00:51:48,340 I was just what I said this is of English so that that works by the way it's shipping in adjacency six point and higher or to seven. 502 00:51:48,610 --> 00:51:54,100 So this is not really science fiction modules is another thing we're working on. 503 00:51:54,520 --> 00:51:58,420 Compilation just takes too long. C++, we have to include model. 504 00:51:58,630 --> 00:52:03,400 It includes all the text, you get a whole lot of text, then the compiler deals with it. 505 00:52:03,880 --> 00:52:08,350 Compilers are superb at compiling a lot of text, but it still takes forever. 506 00:52:09,190 --> 00:52:12,760 So we want to do better. We want to define modules here. 507 00:52:13,000 --> 00:52:17,930 I'm defining a module called the map and. And the map printer. 508 00:52:17,990 --> 00:52:24,260 To implement that I need airstreams, i need containers and I want to use namespace city. 509 00:52:24,440 --> 00:52:32,090 Notice I'm saying import not uh, what you call to include and these export something. 510 00:52:32,240 --> 00:52:42,980 The idea is that when you include you get what is exported and the module itself is a semi compiled construct that is self-contained, 511 00:52:43,610 --> 00:52:51,920 semi compiled once and then expanded where necessary and that is very significantly faster than includes. 512 00:52:52,250 --> 00:52:56,480 I have seen real live examples that compiles ten times faster. 513 00:52:56,990 --> 00:53:01,520 So we're going four factors here. If I get five times, I will be happy. 514 00:53:01,730 --> 00:53:07,480 If I get ten times, I'll get even happier. If you give me 40%, I'll be sad. 515 00:53:08,210 --> 00:53:15,320 This is this is ambitious. And so here I am going to export a template that prints maps. 516 00:53:15,440 --> 00:53:23,780 It takes a sequence, and the sequence has to have printable value type, the key types and a printable value type. 517 00:53:24,110 --> 00:53:28,670 And then I do for all key value appears in print them out. 518 00:53:30,090 --> 00:53:34,600 Now I want this to work. And she proposed 20. This works today. 519 00:53:34,620 --> 00:53:37,800 It's called Structured Bindings. It's part of C++ 17. 520 00:53:39,240 --> 00:53:45,540 This works in the Microsoft implementation, and the concept works in TCC. 521 00:53:46,020 --> 00:53:51,630 When I first wrote this slide, this worked only in plan and see why I want a standard. 522 00:53:52,110 --> 00:53:57,570 I want all three in all platforms I'm using standards are really useful. 523 00:53:58,050 --> 00:54:05,790 So how do we go through to evolve? The language is getting bigger and more complicated and the users are more busy than ever. 524 00:54:06,120 --> 00:54:12,030 So what I want to do is to answer the question, How would you like your code to look like in five years time? 525 00:54:12,570 --> 00:54:16,139 And if you think very much like today, I think you're on ambitious. 526 00:54:16,140 --> 00:54:17,760 You should we can do much better. 527 00:54:18,210 --> 00:54:25,980 So I'm doing it tagging with a sort of a drug cocktail through language design, coding rules, a library and some static analysis. 528 00:54:26,340 --> 00:54:31,649 And I'm after type and resource safety and I want to eliminate all complex techniques 529 00:54:31,650 --> 00:54:36,990 by analysing complexity and throwing things out if they correlate with bugs. 530 00:54:37,650 --> 00:54:41,250 And so basically, this is the Holy Grail I'm after. 531 00:54:41,430 --> 00:54:46,210 There's a project called the C++ Core Guidelines, which is a joint project. 532 00:54:46,230 --> 00:54:50,070 You can find the current guidelines on GitHub. 533 00:54:50,460 --> 00:54:54,540 It's a joint project between Morgan Stanley, Microsoft. 534 00:54:55,610 --> 00:55:01,220 Red Hat, Facebook and a lot of others, which you can look up in the contribution list on GitHub. 535 00:55:01,730 --> 00:55:05,450 I encourage you to note Microsoft and Red Hat. 536 00:55:06,260 --> 00:55:10,220 There's not many joint projects between those two organisations. 537 00:55:10,550 --> 00:55:13,900 I think we have seen progress here anyway. 538 00:55:13,910 --> 00:55:19,610 So what I want. It uses the guidelines and then has a small support library. 539 00:55:19,610 --> 00:55:22,370 By small I mean about a dozen abstraction, similar ones. 540 00:55:22,610 --> 00:55:29,720 And I want static analysis that is work in progress so I can write type and resource safe C++, 541 00:55:29,930 --> 00:55:33,499 but I want it guaranteed and we are working on those guarantees. 542 00:55:33,500 --> 00:55:43,970 But basically no leaks, no memory corruption, no garbage collector by the simple trick of not having any garbage, no limitations on express ability. 543 00:55:44,090 --> 00:55:48,500 I don't want things safe by making sure you don't say anything interesting. 544 00:55:49,520 --> 00:55:55,940 We need still C++, no performance degradation, so we can't just test things at runtime. 545 00:55:56,300 --> 00:56:00,550 Still ISO C++. I don't want to design a new programming language. 546 00:56:00,980 --> 00:56:04,880 It takes forever to build. It takes forever to get deployed. 547 00:56:05,630 --> 00:56:12,860 Basically, the minimum penalty for designing a programming language that works is ten years of manual labour, 548 00:56:13,160 --> 00:56:20,750 meaning you have to work on the manual for ten years. And I wanted to enforce it. 549 00:56:21,440 --> 00:56:27,200 And so basically, I want to get rid of code like this here is innocent looking quote unquote with a delete in it. 550 00:56:27,500 --> 00:56:31,700 There's a new Aquila function and I use it. This is disaster. 551 00:56:32,680 --> 00:56:36,580 Because by the time you get down there, the object doesn't exist anymore. 552 00:56:37,000 --> 00:56:40,329 So this one either reads some memory, which is not the object. 553 00:56:40,330 --> 00:56:47,740 That is just the point I used to point to. It may actually write your favourite data structure and you have the most mysterious bugs you get. 554 00:56:48,130 --> 00:56:52,210 The problem with dangling pointers in their use is you can't see them. 555 00:56:53,050 --> 00:57:00,550 That's why I chose this picture of a nightmare. Never let a point out lived object is point to easy to see how to scale. 556 00:57:00,710 --> 00:57:03,940 I mean, density said it's been there forever. 557 00:57:04,540 --> 00:57:10,420 Okay, so once you get rid of that one, that's all about unions cost. 558 00:57:10,780 --> 00:57:13,840 Not a point of view references. We can do all of that. 559 00:57:14,800 --> 00:57:19,300 This, this this monster is less dangerous. You can see him and you can drain. 560 00:57:19,810 --> 00:57:23,670 Drain his pond and your home. Okay. 561 00:57:25,140 --> 00:57:32,190 Just to show this is not science fiction. There is a printout from the from from Visual Studio last year. 562 00:57:32,670 --> 00:57:35,940 I have a track there that contains two pointers. 563 00:57:36,210 --> 00:57:47,160 I make one of them here and the other the analyser objects because I'm throwing away the information that there was a new once it's up here, 564 00:57:47,160 --> 00:57:52,650 the information is gone. Therefore, we have a potential leak and it will not like it. 565 00:57:52,660 --> 00:57:58,590 So we are deploying this kind of stuff now and basically there's a lot of challenges left. 566 00:57:58,980 --> 00:58:03,300 I didn't say C++ was a perfect language. Never have. I doubt I ever will. 567 00:58:03,630 --> 00:58:06,780 There's lots of challenges left. The world is changing. 568 00:58:07,970 --> 00:58:12,630 We must do better. I mean, our civilisation depends on. 569 00:58:13,720 --> 00:58:19,870 Software. I mean, if if our software really broke, we will end up starving. 570 00:58:20,260 --> 00:58:24,760 This is not an exaggeration. It's it's we have to do better than what we are doing. 571 00:58:25,180 --> 00:58:31,600 And it has to be done on an industrial scale. And staying coherent is hard. 572 00:58:32,320 --> 00:58:38,170 And so I reached my my limit here. And we have time for a few questions.