C++ 20: Reaching for the Aims of C++

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

To me, the most promising part of Bjarne's talk was the stuff about modules and mostly eliminating the preprocessor (41:21-50:05). This starts to address one of the biggest weaknesses of C++ these days, which is the complexity of building a large application that depends on dozens of libraries from various commercial, open source, and internal development sources. In particular, I look forward to retiring the debugging technique of compiling with the -E option to see how a source file was expanded by the preprocessor.

👍︎︎ 7 👤︎︎ u/emotionalfescue 📅︎︎ Dec 20 2021 🗫︎ replies

C++ has it hard. It kind of has more competition now; Go, D, Rust. Even modern Java is looking better than old Java (still too verbose though). C# is also cannibalizing on C++.

TIOBE ranks C++ at place #4 and while C++ won't go away for a long time, it has it much harder than, say, 10 years ago or so (I'd say 5 years ago already, but some of the other languages are also older than 5 years, and it takes a while before competition becomes "serious").

👍︎︎ 15 👤︎︎ u/shevy-ruby 📅︎︎ Dec 20 2021 🗫︎ replies

I think C++ is experiencing a completely normal renewal, and after listening to this talk, I am tempted to actually go back to using it after they get the 2023 version out. While I think Rust is brilliant (especially the compiler), as Bjarne put it in the talk, these new languages are in a very different phase in their lives. C++ is not going away, and is a very solid language. Have they made all the right design decisions? No way...but they have definitely made for a super solid track-record of MANY design decisions with a pretty fantastic success rate...let's see where Rust ends up in 10 years time...Go may steal some thunder in the server apps space, but that may not last, if C++ fixes the compile time and package management problems. C++ has made incredible progress in a very short time to fix many issues...Rust, Go, et al only serve to motivate the C++ standards team to be bold and brave in pushing forward to make for a C++ re-birth...I feel 2025 will be the year of C++

👍︎︎ 2 👤︎︎ u/watr 📅︎︎ Dec 21 2021 🗫︎ replies
Captions
i'm now going to announce uh introduce our opening plenary we decided to do something a little different this year we're going to have bjornik strusstrip do our opening plenary [Applause] so yarn i have something for you you're you're going to need that you're going to need that the reason you're going to need that is because people are going to be going to the to the conference store and they're going to be buying things that you need to autograph god so uh this one is this one is for you and i'll put it here and it can watch you thank you very much okay yeah you never know what's going to happen around here um so i'm i'm going to talk a little bit about c plus plus as i usually am and this year it sort of comes from a pair of questions that i get in some form or other every two weeks or thereabouts one is along the lines why did you invent c plus plus and what it was meant to do and the other one what is c plus plus today and does it have anything to do with what it used to be and there are people who who wants the different combinations of answers of those things like it really shouldn't have changed or it was really good at change completely and i'm i'm going to tell the the story as as i see it which is a little bit more complicated of course you don't actually survive for 40 years without change or without stability so i'm going to talk a little bit about where we started and then i'm going to talk about the book i wrote in 94 trying to articulate the principles of c plus plus and then i'm going to talk a little bit about uh what i can dream about about c plus plus 20 in other words what what will that deliver for us and so how we grow a language how we maintain coherence direction and how to stay true and also how to change as we go along c plus plus was born at bill labs in 79 that was a great place that's murray hill there the the you can see the the arrow down through the uh that's the left of the slide uh shows where all the software stuff comes from and the other end of the building is where we got the hardware and there was great people great technical environment you could always find an expert on anything you would interested in you could walk into their office and they're usually patient even for young researchers like me and it's doing contact with a lot of them and one of the things i learned was that they had this idea that innovation was the combination of invention and development that is it's not enough to have an idea you actually have to work on making that into something real and useful on the other hand it's not enough just to work your butt off and do a lot of work because if you don't have any good ideas it's just wasted and so that kind of combination was was important for my thinking and then finally there were so many problems in that building this was they were running the communication system for for north america and beyond and anything that had anything to do with communication including computing including transmission including radio astronomy uh what was in that building so there was lots of challenges um to make it interesting and so the earliest idea i decided that i was going to build a distributed system there was not many of those at the time if i'd succeeded we would probably have got the first unix cluster out of it but basically i decided i needed to use hardware efficiently and i need to manage complexity you need that for a distributed system and there was no language that could do both the hardware and the abstraction bits and so i uh thought that i could just take a similar class system put it into c and i could get both and so there's the overarching aims and you have to realize that the time was different that's ken thompson and dennis ritchie working on a machine that when we got networking it was called research and that actually was the machine where c plus plus was started on you could get 256 kilobytes of memory for your programs and that was sufficient at the time so there's a different world but if you if you look at the overarching aims they're they're not that different from what we what we hit today and in the in the earliest days again the first month or so i decided i had to stick close to c i did not want to teach people how to write a for loop i mean everybody who can write systems programming can write serious programming knew how to write a loop and we we had some nice ones in c and my my statement was that my mistakes i'll make mistakes if i designed a new language and it's unlikely that my mistakes are less bad than dennis's and we know dennis is so let's let's stick to it that's the beginning of compatibility gave tool compatibility it gave performance on the other hand the type checking in classical c was atrocious and i couldn't live without it so i took the ideas which came from simulan just about any other language and say going we want strong static type shaking that's the ideal but it's really hard to achieve when you always have also have to do cool and unusual things to hardware and also i found over the years that compatibility is even harder than i thought some of the problems linger to this day and evolution was essential it was perfectly obvious even to me that i couldn't build a perfect language and so you shouldn't try you should try and build something that can grow into something that's much better i started thinking about things as a tool and then i realized i was designing a language and then i realized i couldn't even define perfect and so you have to set up feedback loops you have to know roughly what you're doing then you have to see whether it works and fix it and so cross plus was designed from the very early days to evolve to change but also i had my ideals i was very keen on abstraction i didn't want to have specific solutions to specific problems i wanted to provide tools so that people could solve problems i couldn't imagine and i wanted general reality because i didn't really know how much i needed to do and therefore i couldn't limit my domain to just the right domain because i wouldn't know what it was and then i mean those computers there they weren't very fast and they didn't have much memory so performance efficiency compactness was absolutely essential and so here's an example of some something done in the previous millennium um c looked like you can see there to the left if you declare a square root function and then chord square root of two if your lucky your crashes you crash because it forgets to turn the integer into a double because i didn't tell it the argument was a double and so you get an unnormalized floating point number and if you are lucky you crash if you are not lucky you get the wrong result so that i started uh fixing so you could declare function arguments then there was default that the type for anything you said was an int so you didn't have to declare it i couldn't live with that either so i fixed the the the the definition syntax while i was added and then i banned call of undeclared functions because well again we have this nasty problem that either crashes or it doesn't and you should hope for a crash um if you're really lucky and you make no mistakes whatsoever everything will work but i i don't like that bit so static checking was the idea this was the first step towards it actually that was somewhat controversial and for at least 10 years c plus plus was criticized seriously for not being compatible with c because it didn't allow the code on the left there people really like their books and you had comments like you you mean i have to look at a declaration to know how what what the call means i mean can't i just write my code and get it right no you can't experience shows that there are people who can get that right and there's not very many of them and i'm not one of them so i don't want to live in that world okay and he was definitely incompatible to create a lot of problems the argument that i could call convert with very little tools about 10 000 lines of c to c plus plus a day at the time didn't seem to impress people this competitive incompatibility became a reason for not liking c plus plus independently why but it's essential for type checking overloading good user defined type consistent linking if you don't have that you you aren't you can't start and some of the problems insisted today if you assign a cloning point number to a character that's i believe still legal and you get truncation and so some of these things are so deeply embedded in code bases in billion lines of code that you can't get rid of them and so to compensate we start saying okay let's keep the compatible stuff you can make your bugs if you really insist but we provide alternatives so linkage was made consistent and initialization was improved and some of the incompatibilities that i've had a lot of trouble with over the years actually didn't come from c plus plus i used to say that the only thing c adopted from c plus plus without introducing an incompatibility was the slash slash comments which of course i stole from bcpl anyway so this is difficult and so the key idea of writing good code in c plus plus is represent concept in code usually as a class and again you have to think back about the world was very different in those days so that that was considered fairly radical because people wanted to write low level code and low level techniques but that make we might have to make code more declarative to to make it more reliable and we have to make more information available to compilers so that they can generate better code and catch more errors the compiler is your friend i was telling people that's the one that finds all the little stupid things that you would otherwise have to start debugging to find and i never like debugging so early examples of the kind of ideas you should represent in code on that list there and unfortunately they're not all in the standard yet so we're not perfect i'm going to go further and further into what we have today but i'm not going to pretend that we were there yet so one of the things that came very very early i think in the first or second week was what later was known as raii apologies for the name but i was very busy at the time and didn't think about marketing and that kind of stuff so basically in my lab book from 79 says that a new function creates a runtime environment for member functions and the delete functions reverse that because we know to build a runtime environment you have to acquire resources and they have to be cleaned up then later i realized calling in the new function that lead functions confused everybody because they thought they had something to do with free store allocation with newer delete so i renamed them constructor and destructor destructor is a bad pun again but i never could resist a bad pod and later in the 80s i started talking about it in terms of establishing class and variants and things like that okay so this was an example i used for a lot of years back in the 80s and 90s basically here is a naive unsafe piece of code i open a file i use it and i close the file except that in the real world in that use f may not fit on a slide may not fit on a on a on a screen and so somebody might write a return statement or throw an exception or something and something really bad happens and if you look at this piece of code the idea of a file handle is missing this just to a compiler to a user that hasn't read the manual it's just some pointers coming in and going out and with no information unless you read the manual and well compilers don't read manuals and a lot of users don't either so we had to do something about it and so in comes the idea of a resource handle here's a file handle it manages the connection to the rest of the system to the operating system and importantly the code that comes out of that is not just safer it's also shorter and sometimes faster that that's the ideals and so that's where we started we got better support along the lines i very soon realized that we had to able to control copying so this is one of the reasons we got operator overloading starting with with the assignment operator and then also constructors of course and so there's a recurring problem avoiding expensive copying i found somewhere and i think 83 that there was a systematic overhead in returning values from c plus plus compared to c and that had to be fixed it took me a week that led to some optimizations there and there was always optimizations that allowed you to return resource handles and such but they were not very well known and they were tricky so eventually in c plus plus 11 we got the move semantics the move operators that control allows us to control movement between scopes and and in c plus plus 20 we got more guaranteed copulation so basically this thread of control of copying carries on throughout the history of c plus plus getting better and better uh that's uh the idea so we started i needed uh operator overloading i needed operators because i wanted to mimic the the way that we used our building types with user defined types square complex numbers was an example mathematical vectors work samples and such so it started with with equality and then it was actually square brackets and parentheses and then um and and or and having gotten that far driven by users from bell labs we got the end and all from the hardware guys that needed the right simulators or hardware and how can you make hardware without having and all and they certainly didn't want to write a and d and or they wanted their notation and so having gotten that we got the the the operators that people usually think about plus and minors and such and we've got smart pointers needed arrow and we still don't have operator dots so we don't have smart references this is a proposal that has come every year since the opening session of the c plus nc committee and people still can't agree on it so a thing that came in very early also was generic programming i needed it to parameterize containers especially vectors with arguments this is worth mentioning because it was not featured very widely in the way people talked about the c plus plus but it was there those macros to declare parameterize things and define parameterize things use them and i was going around saying that we absolutely need to have parameterized types and macros as a way to do it well i was half right we needed the generic programming and macros are awful they don't scale they work very well when it's two people sharing an office writing code but it doesn't scale beyond that so we have to get back learn from experience know what we want and then carry on object-oriented programming was a really big deal in the 80s and 90s it was invented in 66 by chris nougal who actually taught me about object-oriented programming uh really great guy and there was a lot of hype in the 70s got no real traction i mean real programmers tm never heard of it and the the few that did uh knew that it was too specialized uh too slow and uh could only be done by uh geniuses kreisten said that if we design a language for which you need phds from mit to write the code we have failed um that's a thing worth remembering and so c plus plus supported object-oriented programming from 84 when i put in virtual functions and things like that and it's it's not bad at it but it was never c plus plus an object or in the programming language never c plus was a language that among other things supported object-oriented programming and if you define object-oriented programming as class hierarchies as well popular you'll see why a lot of my favorite types a lot of the types you saw in the beginning slide there doesn't fit into hierarchies okay now c plus plus started to get popular and that meant that a lot of people was explaining it to a lot of other people what it was and what it wasn't and they were getting it wrong quite consistently and so prompted by some rumors of a history paper i was writing i was asked to write a book and i wrote the design evolution of c plus plus the purpose being to explain what c plus plus is why and what the ideals are and basically i realized that articulation of ideals about ideas is absolutely essential i've been so busy that i was saying to people this is what you can do this is what you can do this is how you do it i didn't say why does it make sense to do it that way very much and so the dna became that and one of the observations by a few people is the c plus plus 20 looks remarkably like the the stuff that's in dne because dne also did a thing that i'd never done before which was to look ahead and says where will this lead us what can we get out of this and so that's what it is if you want to to look at the details more look at my paper for the history of programming languages conference uh the one last year you can also look at the one in in 94 because there's several but the the harbor four paper is a good explanation of these ideas and so there was a set of general rules articulated in um in dna like evolution must be driven by real problems i mean i i had a dread of listening to the theoreticians we had who told me exactly what was necessary as opposed to listening to my users who had different ideas of what was important and so i was wanting to listen to the users i knew i couldn't do perfection i knew i couldn't have a research project going for five or ten years before delivering anything had to deliver something now and now really meant well this week usually and always get a transition path from the past to the future make the features affordable i was writing code for people who didn't have the latest supercomputer available not not for the people in the academic departments where they had hardware for millions of dollars given to them it was more the little computers that the the more or less average programmer could use the the research computer that i showed you the picture of that i started out on uh had the not just 256k of memory for everybody it so it served 40 researchers and we never saw an echo delay i can't do that on the supercomputers we're using today echo delays it should have gone out with the previous millennium or before okay okay so articulating all of these things and then explanations of what what they meant um i i'm shooting you've seen a lot of these principles and also there was a language technical rules where the first one actually was no implicit violations of the static type system anybody who has written c and c plus plus know that that is really hard to provide but we're getting there providers good support for user defined types as for building types a very key early thing and make things explicit say what you mean make things declarative and i soon learned that synthetic matter is often in perverse ways people really love the strangest notations and you can't guess what they are sometimes they love things because it's complicated so they can show how smart they are but there's no um no no no guessing what what will be a pro would be approved of and there was a few things that was missing in the uh articulation you you find discussions about simplifying things they're all over the place you find discussions about error handling but it was not articulated well and we still suffer from that also dna gave a direction of evolution it did not give a detailed prescription um this allowed a lot of people to contribute you'll see some pictures later and you you should know some of the names anyway but it was not an organization it didn't channel effort and quite often the problem with c plus plus is not that it doesn't have a facility but that it has 20 varieties of the facility because a lot of people could and did contribute so c plus plus evolved and it grew over the years it grew as a language and it grew as a user community from well zero and to well over five million these days so the dna kind of period the early period is is that down the bottom there you can see we got the the classes and function declarations cold chains const operator overloading things like that and so this is where the standardization starts and the problem of keeping things going being level stable comes into the place and it grew rather nicely for quite a few years despite lack of resources lack of organization lack of marketing things like that okay so why did you work i mean there was no doubt that in a lot of people's mind that c plus plus shouldn't have worked it shouldn't have survived um i have heard c plus plus declared dead uh every year well since 79. so i'm a bit um partly surprised that it didn't because lots of people who proclaimed it dead like the u.s government has a lot of power and uh i don't have it so why did it succeed and i think one of the reasons there's some reasons there why i got the liftoff from older languages why survived is that it enabled new programming styles significant improvements in scales of projects that was manageable the management of complexity it increased productivity it lowered the error rates that was measured and it allowed us to build better libraries without sacrificing performance at the time most people that worked on creating languages to handle complexity said okay machines are getting really fast we don't need efficiency anymore and then they come up with something that are 10 or 100 times lower than c and then people try and write it they love those languages and then they say well wait a minute i can't afford to deploy my stuff so at the time essentially all of ai was done in lisp and whenever they wanted to actually sell a product based with artificial intelligence in it they translated it into c or c plus plus so there was no decrease in performance that was important and this generality again it did not narrow into a language for say gui based programming or something like that that was a popular idea of narrowing or narrowing it into a numeric computation or something like that and i did not insist on purity of the current fashionable style and i got so much many complaints from that i was supposed to go around saying that we need a pure language and at the time i was rather annoyed you don't say purity is for nazis um i mean i don't claim to know how everybody wants to write their code and i get rather annoyed when somebody comes in and think they know and i know they don't i okay so there was no insistence of purity stability was good not perfect but good and getting better and it was culturally compatible with c and other things and it was tool compatible those are i think are the summary of why c plus plus didn't die early as it was predicted and so key foundations the static type system with equal support for building types and user defined types both value and reference semantics systematic and general resource management the scope based stuff from constructors destructors efficient object oriented programming flexible and efficient generic programming uh compile time programming that has increased in importance over the years and direct use of machine and operating system resources that was always important and there's always a problem because you know the hardware and the operating systems can be rather weird and they are also incompatible across the user base if you want to deliver a product or the major popular platforms and computers the access to the hardware and to the operating system is a really hard thing to do portably and so the hover papers describe this and so here's that slide again and we are now up in the top uh top right corner and we have lots of good stuff we have c plus plus 20 c plus plus 14 and 17 are still being rolled in in places people are still trying to catch up with what we've got and so the question is can that blob deliver improvement to the community comparable to what it was in the early days by the way that dip around 2000 came with the most massive hype for for java c sharp and for managed environments big systems and then we ran out of compute power the single thread single thread performance stopped because we were starting to fry eggs on the chips if we went any further and we went into more clever architectures more different uses of of of the transistors and so certainly again good programming good programmers could outperform a system that couldn't quite use the hardware similarly a lot of people realized that every platform owner had their own private language that they wanted you to use and if you wanted to deliver across platforms you better do something else and c and c plus plus tended to be the answer to that so will c plus plus enable the liftoff from the world of c plus 11 that we are currently living in most of us and yes i think so i consider it possible even likely but not without significant effort um we we need to teach ourselves in the community how to use the facilities well and we need to develop further support for facilities in the directions that we're working for and we have to see c plus plus an ecosystem i can't spill okay and not just a set of individual features there's so many papers and pres and presentations it says look at this little corner and and look at all these clever things i can do here that's quite distracting and it turns off a lot of people that are not in the community already and if there's anything i dislike for a talk it's the one that says look at this code it's really complicated you don't understand it i understand it so i'm smarter than you any talk that has that format i i don't like okay so we have to focus on the whole community the whole [Music] tool change and design techniques etc and we have to focus on use what what should be done what not just what can be done so i'm going to talk about that for the rest of the talk here and i'm talking with the idea that we need to have a direction we can't just pick anything that looks fashionable at the time if nothing else because fashions change but also because the language would become incoherent the aim is a dense web of interrelated mutually supportive features that's a big sentence but it is the opposite of just adding features so that you get the swiss army knife model of language most of the code we write doesn't use one feature at a time i don't want to do object oriented programming or generic programming or functional programming i want to take the bits as they fit my problem area and use a combination of them and i want the language features to support such use of a combination and feature interaction is very hard problem combination of features is a very hard design problem and a usage problem so when you should focus on use i'm thinking mostly about management of complexity and and one of the slogans i have is to make a simple task simple uh and and of course not to make it impossible or unnecessarily hard to do really complicated things and that leads us to some notion of layers of abstraction it leads us to clean interfaces and it leads us again back to the static type safety so that i can trust my interfaces it leads to resource management in many many areas and it leads us to looking at error handling and so the idea is you can tune a program ideally you start with a really clean safe interface and if you need something that is more specialized and takes advantage of special things you can do that you peel a layer of the onion and if that's not good enough you peel off another layer in the end you get down to the hardware and you use specialized hardware all the way down and the reason i call it the onion principle is that each time you peel a layer off your cryomore uh it's uh you when you take away from the clean safe interface you you pay for it in in work okay so there's been a lot of contribut contributors to this uh the standards comedians are the obvious that's where you get a name but also a lot of tool builders a lot of application developers i'll show a couple of pictures but if i should mention even a lot i would use the whole talk so thanks to everybody but i can't mention everybody just now and then i'm going to pick some topics from the uh the index from dne and see how it reflects in in modern c plus so the zero overhead rule comes in again and again it was for a long time the sharpest knife in our vocabulary in our tool set what you don't use you don't pay for that's what keeps c plus plus distinct from some of the managed languages and what you do use you couldn't hand code any better that is we don't want people to drop levels of abstraction too soon without need for it and this is a constantly pervasive effort and it it it comes to this idea that you you it's not enough to be able to do something you have to be able to afford to do it uh you have to be able to afford to do it in the environment you're in on the kind of computers you can afford to buy and run um i took a little example there matrix sum equals m2 plus m3 that should generate code that's at least as good as if you are fiddling directly with arrays and for many decades at least three decades we've been able to do things like that so that it actually runs faster than most hand written loops that's the kind of idea that we're dealing with no implicit violations of the static type system that's hard to do and have to increase it then he said that c was a strongly typed language that was weakly checked i would like it to be strongly typed and strongly checked and so one idea that i discussed with dennis and dennis wanted something called fat pointers a fat pointer is simply a pointer with an associated uh size so that you could loop over the um the array without getting a overrun and actually so we have now span in c plus plus 20 and so a span knows its size and you can go for all elements in that and since the size is known you don't actually have to check check the range there so we don't run faster than a lot of uses and so language requires static type system to be obeyed that is the rules it's just been too hard to do and we're not completely there providers good support for user defined types as built-in types we're getting there one of the last things is user-defined literals so that we can have uh constants that that has proper types so that's said there 2i plus 3 is obviously a complex number and there's a date there from the c plus plus 20 standard library october the 25th to 2021 it compiles actually at compile time into a time point which is just one value so it's not just clean and readable it's also about as deadly efficient as you can get it pre-processor usage should be eliminated i i really really dislike the preprocessor and i would like to write code like you see there there's no sharps in that piece of code import the standard library use the namespace chrono and do some manipulations with dates and over breakfast i ran it and it says that we are in denver on the 25th this year this month okay and again this is not a single facility that says okay here is the alternative to the preprocessor it picks off things that the preprocessor does and are worth doing and then provides better alternatives more strongly typed more easily checked more easily generating code for less error prone etc um and so basically um we we re we can overcome compile time overheads we can get rid of bugs and one thing that people tend to underestimate when they look at the one little macro isn't too bad is that it cripples c plus tool building what the compiler looks at is different from what you look at because the pre-processor did strange things to your code and that has bothered the c plus plus tool community for ages and so um i actually said so in design evolution of c plus plus that was the main reason given why uh the preprocessor was bad and we need an elegant deficient common non-textual representation of c plus plus we we don't have something that um that does all of those things but i think gabby does raise will give a talk about something that is along the lines that i'm thinking about at this conference modules was one of the major things that was coming in to to help make the preprocessor redundant it was always the ideal i discussed this with dennis um the the one definition rule odr is there to pretend that there's only one exactly one definition of every entity in the program dennis and i agreed that was it and all the rules the pages of rules are there to fudge it in a world littered with a preprocessor includes and defines and we now have module definitions and imports that can realize true odr as we want to it's going to be very hard to deploy at scale there's uh 20 there's 50 years of practice with the preprocessor lots of tools are optimized for the preprocessor lots of people have um macros and includes hardwired into their brains so but we're going to get there because there's major advanced advantages the major advantage of module modules are simply modularity if i include two files then if i do it in the opposite order i might get a different answer that can give surprises and it gives overheads in the compilers furthermore includes a transitive so if i'm using one of your header files i get everything that you include to build your header files modules are simple they are if you import two it doesn't matter which order you import them in and imports are not transitive so there's far less information to deal with this is really hard but we can do it and there's an example of a module i want to export a sequence printer the smallest module i could fit on a slide and to build my sequence printer i import io streams i import i use the namespace std which you know you shouldn't do in include files because that would be be exported but it's not exported here just an implementation detail so is my utility library that i built myself had nothing to do with it and then i can write the one function that i export that that simply prints something that is printable i've defined myself a concept printable input range so that i could specify that again notice the feature combination there there's a range four there's a concept for staff for generic programming and there's the module facility here i borrowed an example for a library from somebody in germany that had a library that comes in two versions you have to have two versions because you have to have your old users and your new users and basically the one includes the library and it takes a second and a half to compile the other one import the library and it takes 64 milliseconds to compile we can't promise you 25 times improvements every time you turn something into a module but sometimes and you should think about factors not a few percent i did a little um experiment because i made a proposal to the standards committee that we had a module std that gives you everything in the standard library so that once you start writing code you don't have to think about where you get it from in the standard library just give me the whole thing it's good for teaching it's good for small experiments it's good for getting started you can do more fine grain later if that's what you want and you can use your own uh modules and such so this is the way i would like hello world to look like in import std out hello modern world and the arguments for including everything in the standard library for large modules is that you can't afford it that happens to be wrong as you can see there the hello world compared to with import std compared to include iostream is a factor of 10 faster to compile i did a little example where i i took nine popular headers and used facilities from them there i only got a factor of five i would say that from from my experience it's not unreasonable think of a compile time speed off of about a factor of of of seven i have seen zero and i have seen uh 80. so it's it's somewhere in that one but there's a lot of to be done in simplifying the code and getting it to compile faster you will not be drinking as much coffee as you used to okay so the modules were done in the standards committee there's the three key people for the three major compilers who did that work and we have to work on now how we use the modules well i mean this example is to say let's use modules in this particular way which is rather different from the way we used include files we should not do like they did when they invented cars they they looked very much like a horse-drawn carriage without the horse and we are prone to do that when we get a new feature and so having granularity of the standard library reflects the 50 years of standard library headers is just not right we can do better than that and how do we distribute sets of modules how do you make modules available for static analysis i'm very keen on static analysis you'll find out and so these are the kind of things that has to be done we don't just have a feature we have to figure out how to use the feature generic programming has been something we've been working on for years my ideal is very simple generic programming is just programming and so when it's there's not any big problem to explain that uh oh again i can't spell so this the first one should of course be square root uh double square root of double we know that we learned that from the beginning and i want sort to be something that you do has audible range for and the design of c plus plus star section on templates starts with three pages of apologies not to be able to do that i didn't know how to do it basically we started out with macros and i looked for templates tried to figure out what template should be general flexible zero had well specified interfaces and realized that i couldn't do all three and i asked around nobody else seemed to be able to do all three either you can pick two and so i picked the first two and then we tried in the standards committee to get concepts into um into c plus plus ox modeled on classes that failed complexity grew too high cost was high and we now have them in in 20 roughly the way they are supposed to be we can constrain the template arguments um now we couldn't until c plus 17 and basically we can say sortable iterators and then sort and then it comes to the question how to define sortable so that you can afford to do it we don't want to do it at runtime because then we would get a massive overhead compared to people that didn't check their arguments and that is against the zero overhead principle it would lead to issues so here's the concepts they're based on use patterns you can define a concept by specifying how it can be used there's a quality comparable of two types and it requires you to um to to be able to do equals and not equals and generate booleans and that works for both different types t and u and you can default to t equals u so it'll work and you don't have to write this because you can find it in the standard library now but that's the way it used this goes back to work that was actually back in the uh in oh six and a bit before that by by gabby and me um and you can compose uh concept out of other concepts which is the way we use it just like we don't usually write all of our code in the language itself we build libraries and then use those libraries similarly we do with the concepts concepts are what specifies what types are required by a template or something like that and so i can say that a sortable range is a random access range you find that in standard library and it has sortable iterators again standard stuff and if i want my own forward sortable range that is something that i can sort even though i cannot get random access i can define it myself like that and then we can now have both um sort functions cooperating that is if you have something with random access you get the the standard version if you have one that doesn't um doesn't have random access you can do without it the simplest way is to copy into a in into a vector sorted and copy the elements back again there's also clever algorithms for sorting things without doing that for a forward range notice that we don't have to build up hierarchies or explicitly defined relationship between concepts the compiler is quite capable of figuring out whether two sets of predicates are subsets of each other or disjoint or such so we don't have to say it so you retain the flexibility of generic programming in rl and getting the the more constrained world of object oriented programming with hierarchies and so we have to represent relationships it is not just types of types because most algorithms take more than one argument and if there's two argument types there's a relationship between those two types otherwise why is it one function if there's no relationship between the types of the arguments and so i find that most templates require multiple typed concepts so concept is a predicate it's a predicate over types and values of one or more types and values and so there's a relation between types and single argument concepts basically a type specifies what you can do to an object and how that object is laid down in memory a single argument concept specifies what you can do to the object but it doesn't say anything about how it is laid down in memory and so my ideas actually is to use concept where we now use types except for defining layout that will lead to much more flexible code and i think without loss of performance and so we can do better than we are now we're not at the end of the thing we have to explore design implementation techniques we have to improve type deduction we have to get better support in the standard library and i still miss actions to say something about the semantics of a concept if you go back to the c plus plus 0x design it had had actions in it they got lost on the way further and i didn't mention as a key support for for templates and generic programming in in dne i did not mention lambdas and variable templates lambda is because i didn't think about it variatic templates because i didn't know them yet there's an example of a piece of code that i would like to write and i can't because we are not quite there yet i get this forward sortable sequence and so i would like to copy it into a vector sort the vector and then copy the the the buffer back again into my sequence and i would like to do it without dropping to the level of iterators when i don't have to we can't do that yet it's just an example of what we might be able to do in the future in object-oriented programming um i it's it's pretty good and i'm not having an emphasis on that but it's it's used far more than it's discussed these days so don't forget it there's two things in dna that that would improve object-oriented programming and its interaction with generic programming which is a multi-method so that you can have a thing that has a dynamic lookup on two arguments instead of just one and also uniform function calls so that we don't have to decide on our syntax based on what the library provider decided for us and so that i can write my concepts simply saying i'm using this and i don't have to know whether it's implemented in a functional style or in an object-oriented style error handling is is a is a big deal it was not specifically listed in the rules of tom and dna and that was a bad mistake because that led me to discuss the issue on the label of exceptions which is not the right label is not that you program exceptions your program error handling sometimes using exceptions and so exceptions were used for separating error handling code for mainline code so that you didn't have to be aware of it all the time and it was never meant for localized error checks and it was meant to be used in combination with raii so that you don't have all of these stray pointers floating around creating leaks when you have exceptions pass by it it was very much a combination with the thoughts about resource management not just the standalone feature and it's a very inflamed topic it's really hard to discuss error handling because everybody has ideas and everybody has ideas about what other people's ideas are and that makes it quite hard to discuss without emotion also there are too many alternatives one of the reasons i did exceptions was to simplify code where there usually was about four different ways of reporting an error and when i had to write in a library i had to take care of these four ways of doing errors non-local errors and then i say we can do exceptions and we will just have one and i ran into the n plus one problem you have four ways of doing things you are going to unify it so that you get simpler and now you have five and because the old ones don't go away and it really is more like an n plus m problem because there are many people who think they have a solution to this problem and so it gets worse and worse if i have to write a piece of code i have to know which of the about 10 ways people write their error handlers today to to be able to write really reliable code and also error handling is not localized to a single domain and how you handle error as well is not an absolute it's something that depends on the degree of reliability you need the degree of the complexity of your code and the amount of hardware support alternatives you have available but it's critically important reliability is a systems issue it's not just a theory issue so there's many alternatives error states error codes exceptions and contracts and we need to make progress here and hopefully that progress is not to get three versions of each of what is on that slide which unfortunately is a fairly likely outcome of of these discussions so two things we should remember is that exceptions have served many very well and exceptions have been unacceptable to many and there's reasons for that the reason c exceptions came in was it handles care handles cases where there's no return value to test that's operators and constructors for instance and it was integrated with resource management and it saved us from pervasive forwarding on off unknown errors you will have seen code where the function is mainly a nest of tests of error codes that comes from lower levels of code and when a new error comes in at a lower level you have to add another error code and such so that's hard on the other hand there's no doubt that we have systems where the exception handling mechanism itself will press out functionality you can have the functionality you can have the exceptions on the other hand if people write code where they want exceptions to be fast i don't think that's what exceptions were designed for and we can improve the implementations of exceptions today we can improve them quite drastically but you are never going to get exception handling in the c plus plus style to be as fast as a simple function call that's not what they're for they are to separate the concerns about error handling and the main line code and so i think we'll always have both exceptions and error codes whether people like it or not and we can do better things and one thing that i look at in every discussion is raii do we lose the connection to to resource management if we do i i don't like it and do not think that everybody has the same needs as you or think in the same way as you do concurrency and parallelism is a major major issue it has been around since the very first days those cool genes in the early seaworld classes c plus plus libraries it was the first cv classes library we would not be here if it wasn't for cool teens this was my bread and butter through the 80s that was what kept c plus alive um unfortunately the trickery i did with registers to implement it couldn't be done on a spark without collaboration from sun and they weren't they were not convinced that cold chains was a good thing and worth spending time on so we lost them but anyway cpr plus 11 gave us a major boost by getting a memory model that could handle what kind of work that was done with cnc plus plus as opposed to higher level models that needed the lower level one also to be implemented and we have made steady improvements of that and coral genes are back i'm really happy about that i've missed them for about 30 years that's bad so cold chains mighty use cases were sequences sequences and generators pipelines and networks of pipes building a application as a network of coal scenes is a way of of doing of managing very serious complexity including asynchrony sometimes and that's we've got it now but we don't have standard support in the standard library for the simpler uses of core jeans and that's one of the things i hope we get for c plus plus 23. and there's a very simple example uh gornisherov was the main supplier of the ideas and implementation that got into c plus plus 20. so basically what you're doing is you are saving the state in between calls of a function you're saving it in a return value so that you can have different ways of saving things different constraints synchronous asynchronous and you can write little code like also for for all v and fibonacci write them out that's an infinite loop unfortunately but it fits on a slide and parallel algorithms is where i really would like to go um if i can get somebody else to deal with the concurrency and the locking or whatever is needed to to write the code and simply i can say simply sort that that container then then i'm happier and we are moving in that direction that has a lot of promise uh if we get concurrency uh to disappear into parallel algorithms it becomes simpler and easier to optimize and so i want standard library support for co routines more algorithms i really find that there's not a find or in the standard library there was a find ore in the task library in 1980 it was one of the first things i needed and the point is that you have to return a container of stuff well we know how to return containers now it's a it's the move semantics right we just built the vector and return it couldn't do that well in the late 80s when the sto came around but we can do better now also i really miss a message queue again this is one of the things that was in the very first uh coaching library and just message queue why don't we have one yes that would have been nice there's other things so now back to the issue of we need stability because we have billions of lines of code millions of programmers we can't just break all of that on the other hand we have to make progress and i i realized that fairly early on and we've been trying to to find a way of balancing these two constraints and my current estimate these days of how to do this best is the c plus plus core guidelines which is basically a group of people's idea of what modern c plus plus should be and that it's evolving it'll be changed we have to distinguish between what's legal the standard has to maintain things to be stable but we also have to move the community ahead we have to see what the ideals are how we can better reflect the ideals the core guidelines goes in that direction and you can find them on the web and you can contribute if you want to and so yeah we distinguish between what what's legal and what's so good even c did that those of you who are around can remember that there was c code and then there was lint to to catch things that the compiler couldn't handle we we need something similar today and the core guidelines are built so that you can write code checkers static checkers that does that and so we can write code that's type safe efficient and maintainable and that's what we can do and so it's essential to enforce the type rules no type violations no memory corruption no resource leaks and no garbage collector general strategies not to generate garbage and no undefined behavior we can do that today but we can't do it without help we need static analysis to verify it you cannot get the guarantees for what i say is essential there in a realistically sized program without without help so selective also you need to bring it in selectively you can't just get from old code with all the messy stuff in to to modern code that that's that's correct you have to grow gradually it uses a strategy of a subset of a superset that is first to extend the language with the with the libraries that you need to do your work well and then you stop use of the low level the dangerous features outside the implementation of those libraries because some of the most dangerous features some of the most tricky features at scale set essentially exactly the ones you need to implement things like a vector or a process scheduler so you can't just take them away and so the strategy is to increase the libraries and then subset and so what i mean did i anticipate all of c plus plus 20 facilities in the 80s of course not i mean there's no way i mean we have to engineer the language we have to learn from experience we have to rely on feedback that is essential as it was and is c perfect no of course it isn't perfect how would you define perfection i mean if somebody comes and tells you they have a perfect language it's well it's either a fool or a salesman or both that's uh it's you can't even define perfect and so we have we are not at the end yet we probably never will be we have to learn from experience and improve things and so this is a talk about um how we got here and the not not so much about future i have of course strong opinions about the future the feature set the technical details so i'll just list it here and once i've made this list i noticed that there's talks about just about everything at this conference so you can go to your program and you can find talks about all of these things work is going on i don't think there's talk about static reflection there should be but and if there is i i missed it but all the other things you can go and look in depth at what i was talking about here okay thank you and i i think we have time for a q a i don't know how we oh there's a microphone there there's a microphone there so two random features and just your thoughts on where they could fit in c plus plus in the future one is continuation passing style and the other is like true immutable values uh truly immutable values i don't have a detailed answer to those um no you you can of course do it but i have not looked into how it will fit with the rest that's the issue we have a question from online oh uh you talked about banning features you do not like what are those um [Music] i i know i can't ban them so i don't think all too hard about it basically my feeling is that the major feature the major feature set is about right and that every detail of every major feature could be improved with 2020 hindsight if you go back you'll see things like the um the thing that has bothered me constantly for years is the fact that the fundamental types the integers and the characters can be converted both ways implicitly i mean that's just not a good idea and it only came in because explicit type conversion was not invented till a couple of years later in the sea world and so if if i could ban it don't convert a floating point number to a character implicitly fortunately a lot of compilers agree with me these days so you can properly in many cases you you can't get away with that but but it is a fact that the early c plus plus compilers gave you warnings that you couldn't suppress for that kind of errors but when things scaled other people were a bit scared of telling their users that their old code really was broken and so they took away those heavy duty moralizing that it was also a lot of the syntax could be much better i i don't like the declarative syntax from c and i think the c plus plus template syntax is far too heavy weight i like the functional notation for templates also we're getting some of it but but not as much as i would like that's i i could go on for a long time probably should so i'll stop now and say take another question so this is one of my favorite c plus books um because it's brief you can maybe get some of your coworkers to read it in its entirety um you can read in your entirety pretty quickly um and it's you know i know it's gonna be good there's a lot of questions so um i'm interested there's a plan for a third edition because the only issue with this right now is it's a little dated and then you're more your longer book um you see the whole language that's made about you know printing about that thick edition of that yeah i there there will be a third edition of that book there will be a third edition of the swan book for novices basically those two books are for for different domains people need to learn to program and people who need to get upgraded to modern c plus the question is when there's a big question about that one should i do it now or should i do it when the outline of c plus 23 is known because i would really like the opening example to be import std and i would really like to be able to describe cool chains at some depth um getting to my favorite networks of of pipes and can i do that now i would have to take a chance and say well there's a proposal for import std and if the standard doesn't get it you'll have to do it yourself similarly there are libraries for coal chains that probably will come in and maybe i'll take a chance i don't know but those are the key issues on the other hand we need to think about how people learn to write c plus plus from scratch there's still a fair number of people doing that and for that it's the swan book that is still at c plus 14 level and the big the big book not any day soon it takes something like two years full time to do and i'm not sure anybody reads something that think anymore so the philosophy is if you can get people started and get people to use the online facilities and the um more specialized books that that may be a better use of my time i guess i've learned the swan book but i meant the larger book i meant like the c yeah i know it's more not necessary for novice yeah that's the one i doubt i'll do okay because i think the problem is to get enough people up to speed so that they can listen to say the videos from this conference and other conferences so that they can look into specialized topics there are books for that i i'm not sure that there is that there's enough people who would benefit from a 2000 [Music] page two volume book that would take me two full years of my life to write all right thank you we have another question from online can you talk about how optimizing code in the 80s was different from today as examples different caches different tooling register management maybe something else i didn't hear that very well it came across very soft could you try and repeat can you talk about how optimizing code in the 80s was different from today as examples different caches different tooling register management and maybe something else yeah basically in the 80s you could understand your hardware and you could optimize based on your understanding of the hardware these days the hardware is just so complicated that you can't rely on that and it is also changing quite often so that you would have to re-tune your code when you get say a different number of calls so i would say that you could rely on your understanding in the 80s you could think about registers you could think about how much [Music] how many instructions you were executing you could think about how much data those instructions got from memory try and do that today and you are fooling yourself there's so much dynamic going on that you don't understand and that you're probably going to pessimize your code by trying to optimize it so you have to rely on the hardware doing dynamic optimization and static analysis and optimizers that can do truly miraculous things sometimes and sometimes do a horrible job if there's a mismatch between what you think you're doing and what you're doing personally i tend to look into a couple of things very simple don't read too much memory and when you read it read it in a predictable way and much things beyond that i would rather leave to the optimizers to do and if i really really have to tweak below that i have to then start looking at the machine architecture on the particular processor i'm using and i don't like to do that because in some sense it's a waste of time because if you want that degree of performance next year's computer is going to be better at it and you will have to do it again this is a pretty old language um and it's been around for a while and you talked about how you know evolution is its process of feedback and so we we developed new layers of the standard every three years and then it takes companies many many years you know still many are like decades behind the standard um and then you compare that to some modern languages like rust which are you know sort of accelerating almost past c plus plus in terms of some of the features they're able to deliver and yeah if you do you have any comments or ideas about how cbs plus can maintain these um you know highly valuable properties of stability whilst uh speeding up the pace of evolution of the language sure i'm not sure i want to speed up the evolution of the language i want to maintain the stability i would like to be sure that i wasn't chasing fads any language that is successful will get the problems of c plus plus i i know there's people who think that they can maintain a modern language that changes rapidly forever but that's that's not really the case once you get to the hundreds of thousands or millions of users and the billions of lines of code and it is not it is very hard to maintain if there's more than one implementation and if there's one just one implementation people will worry so i i'm not too worried we have to carefully improve c plus plus maintaining maintaining compatibility maintaining stability and if some things can't be improved say a library that can't be improved build another library and let people use the the new library and fade out the old one [Music] and yeah people have been predicting c plus plus death every year for the last 40 so i'm a little bit reluctant to believe uh the current things new languages either cease to be new or they die and if they cease to be new they have to face the problems of stability versus evolution and how to get novel features in and deployed and taught or if they're not successful well they don't have a problem uh hi uh kind of similar question it seems like c plus plus has been influenced by a lot of other languages and you you have a lot of experience with other languages around design so i was curious um how you see c plus plus interacting with other languages uh languages like managed languages or men or languages like rust do you still pick up um features or ideas concepts from other languages or yeah just how does that relationship yeah this is the kind of question i get a lot and i think it's slightly misraised um it is extremely hard to adopt a feature straight from another language what is really happening is that ideas are around in the community in the academic world for for many years before they get fashionable in any language and you tend to be aware of new features long before they become fashionable and so there's a much longer gestation period for novel features than people are thinking about i mean auto i designed and implemented in 82 or 83 and then it was kicked out it was not something i got from languages using lit similarly range 4 has been around since the dawn of time basically what is it invariants and such was pioneered in the seventies and such so what you do is you try and see how ideas are presented in various languages and try and estimate to which extent they are successes and in which sense they are successes for the feature set in another language and whether they would be still be successes in the feature set of c plus plus usually when a language feature is is adopted as i said it comes from back in time and probably inspired and observed from other languages but also with very careful notice about feature composition in in both the language you're looking at and in c plus plus but uh it's it's something that i'm very aware of and i tend to look at the feature composition as the key issue so in this talk and in your books you're not shy about your dislike of the preprocessor and we're gradually on our way to eliminating a lot of the need for it but one of the things that it still does better than anything else is generate code and i know there's the metaclass's proposal but i don't see this on the future what is your opinion on code generation in the language um the first line there is a static reflection it is on there and yes that is there and i know that in some cases you can build better code with the preprocessor i also know that many claims a better pro code with the preprocessor or better code from template meta programming are simply not true that is it is really really important to measure and especially in sort of published stuff people tend to get excited with some technique or another and it will give a better result for a very narrow domain so first i'm going to be doubtful and second are going to point to to templates as a way and constant constant evaluation for compile time evaluation for alternatives to uh two two macros and that was on the slide and then finally first line on the slide that happens to be there uh i had hoped something would happen for 23 but i've given up that hope it's not going to happen till at least 26. hi brianna this is not so much a question um uh i really wanted to thank you uh for a number of things when the first you know whenever i see you talk about the history of c plus i always feel this immense pride to have had some small part participating in it but also you know i hear when you talk about the basic values behind of language design that you have applied here i hear my own values and i realize i learned those from you i learned those from in your community and uh my participation in the c plus community was probably the biggest learning experience and career changer in my entire life so i i really want to thank you for for opening that opportunity for me and opening the world up well um thank you very much that's very much and welcome back okay just i'm curious about that do you have any plan to extend uh a standard algorithm to support some well-defined areas such as you know algorithm about the graph processing or machine learning or just i wanted to know maybe it's uh it's better to use third party library and there is no plan to stand our guys this type of algorithm this is hard it's one of the fastest moving fields there is and c plus plus is deeply into aiaml with tensorflow and libraries like that but also the hardware is changing very fast i don't see the standards committee being able to do something in a couple of years it'll take longer so i think it will have to come from what you call third party and um there's a talk by mike wong and somebody else at this conference that that might touch upon those kinds of things so i suggest you go there it's it's not something i have plans for at most i have some hopes acknowledging that there's many answers to what belongs in the standard library um what would you say are your criteria or philosophy around what you think does belong being standardized into the standard library um i articulated an idea for the c plus plus 98 library which was basically what it took so for what was needed for separately developed libraries to communicate and inter-operate and and that's still sort of the rock bottom of of the way i look at it similarly modeling the underlying hardware is part of that and so the the the massive work that was done for c plus plus 11 for the memory model and for modeling the the thread and lock um um style of concurrency was absolutely essential and and currently there are work on uh what's called executives for creating a more general model of concurrency which again fits into this pattern says how can my code communicate with your code especially if this is asynchronous path in between so that's that that's that's my fundamental thinking but then there's a completely different area where the c plus plus library has been not very well served compared to the massive commercial libraries that can throw money at it we don't have any money and and that is a particular area that is needed by a lot of programmers think about a json library a json parser things like that they exist and they're good and we have a dozen or two dozen of them and none of them are standard and it would be nice if the library could get into that to create a standard but it's not easy look at the look at the regex library that that sort of got complicated and seems to have become a bit old-fashioned faster than it should so things that you need to communicate to collaborate and things that everybody needs and we are i think reasonably good at the former and not all that good at the ladder look at the graphics library and things like that it's hard okay i think we are timed out thank you very much you
Info
Channel: Coding Tech
Views: 12,507
Rating: undefined out of 5
Keywords: c++, c++ programming, c++ 20
Id: TeduHyHdH3A
Channel Id: undefined
Length: 97min 56sec (5876 seconds)
Published: Thu Dec 16 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.