Why C++ Sails When the Vasa Sank

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] the last three days I've been here and I've normally only understood Scott Myers and C++ but this time I'm pretty sure I heard something about pizza so I feel like my vocabulary is growing constantly I've spent the last three days talking about extremely technical aspects of C++ that's not what I'm gonna talk about tonight tonight I want to talk about something completely different what I find is that for people who don't program in C++ and have heard about C++ all they can think of as why would you use that language and for people who do program in C++ in some cases they find themselves saying why am i using this language and I think it's interesting to sort of take a step back from the technical details from time to time and ask ourselves why are we programming in this language I mean there's a reason why people are using C++ and it's not because it's necessarily the most fun language in the world or because it's the most exciting language for other people so there's got to be something that is compelling people to use C++ so that's what I want to talk about tonight a little bit is why we've got C++ in the first place and what I want to do is to take you way back in time before some of you were born and talk about C++ in 1990 to 1992 they're just beginning to think about standardizing C++ and everybody wants to get their favorite feature into the language I mean this is going to be the chance to make your mark on C++ so there's a huge stream of standardisation proposals everybody wants to do something new and the standardization committee starts thinking man this language is going to be so big and so complicated that we really have to be concerned about what we're building and I want to point out this is 1992 the standard template library does not yet exist so we're talking about a serious concern about complexity before there are before the STL existed the language was much simpler than it is now and so the standardization committee said we've got to try to do something about this and my favorite quote from about this was from Jim Waldo who was on the standardization committee at the time and what he said was we should have a rule but every proposal should be accompanied by a kidney because that way no one would submit more than two and they'd only submit really important ones and of course the C++ farmer said does it have to be your own kidney or could it be someone else's kidney so still this huge stream of proposals and so garna was also very concerned about the language and garna said listen c++ is already too large and it's too complicated for what we prefer and then he said remember the Vasa and everybody except the people from Sweden said what's the Vasa no idea what no one can remember the Vasa so the Vasa was a famous in Sweden sailing ship it was commissioned in the 1600s and originally the idea was we need a sailing we need a warship that's what we need and they send out blueprints and they hired people to build it and all that kind of good stuff and then as it was being built the King said you know it'd be nice if we did this so why don't you add that to it and then they said you know actually instead of having one deck for cannon let's have two decks for cannon that would be a lot better oh and can you take the ship and make it longer that would be really and you don't say no to the king so all these things happened so ultimately the ship was delivered it was extremely heavily armed looked really good in Harbor was very very heavily decorated had a little bit of a problem so on its maiden voyage it sailed a couple of kilometers and a lot of people died ship collapsed went into the harbor it's actually in a very nice Museum now in Sweden because it was in really good condition and it didn't go very far but it also didn't sail which is not so good for a warship you really would like your warships to go somewhere so the analogy was you know remember you built this sailing ship and I made it all decorated and very very heavily armed and everybody loved it on paper and it collapsed and people died and the idea was we don't want that to happen to C++ and if you take a look at C++ you sort of say well all right I mean is it heavily armed that's kind of a lot of features my favorites here are two kinds of me neumes we've got three kinds of memory models three kinds of references three sets of rules for type deduction by the way this is wrong there's not three sets of rules for type deduction this is an area I've been looking into recently there are six sets of rules for type deduction and I am not kidding so I think this is a heavily-armed language it's got a lot of ammunition and in terms of I mean is it ornately decorated so consider the really simple expression f of X you're reading some source code you see f of X invoke F on X really simple I mean what what could that mean if you're reading it well F could be a function or a function pointer or actually a function reference because we have those in C++ too well actually F could also be an object of a class that overloads the function call operator so it could be one of those actually it could be an object that's implicitly convertible to one of those things that would work too you know it could be an overloaded function name there could be a whole bunch of functions named F and of course they could be declared at multiple scopes so it could be that two you know it could also be the name of one or more templates which could be also declared at multiple scopes actually it could be the name of one or more template specializations as well you know actually it could be all of these things simultaneously pretty much so we could have overloaded function names we could have overloaded template names we could have template specializations I'm beginning to think I understand why people think this language is kind of complicated I mean this just doesn't seem as straightforward as we would like this is a quote from someone else who was active in the community very important in 1990 1990 that was a hundred years ago 1990 so Tom gargle said if you don't think C++ is too complicated just what is a protected abstract virtual pure private destructor and when was the last time you needed one and it is very sad because when I read this I went hmm well okay that means this I mean I knew immediately what he was talking about which really is so sad and I have never needed one but that is legal C++ you can actually have that given that C++ has this enormous array of features and all these funny rules and if you look at an expression like f of X you can't say what it means it's a little surprising that C++ has been as successful as it has but it must have been doing something right so there's a couple of ways we can try to measure how successful a programming language is one of the things that people like to look at in recent years is the Taiyo be programming index which is an attempt to measure how popular a language is it looks at things like job listings and mentions on blogs and news groups and various kinds of discussion one of the interesting things is that this is the last ten years of data so this is C++ its popularity in 2002 it had about a fifteen seventeen percent market share now you can see that it's gone down over time and there's been a real drop recently but I think that's kind of a blip to be honest but you'll notice that pretty much all the more popular languages like C and Java have also lost market share in that time but if you look at a longer-term perspective C++ has been either the second or the third most popular programming language that has been measured in the last 25 years for all except the last year it is only within the last eight or nine months that it went to position for when Objective C overtook it and whether that will continue to be the case remains to be seen when you have a programming language that is one of the top two three or four programming languages for 25 years it's got to be doing something right there's got to be some reason why people are using it another thing we might look at is well alright what percentage of projects that are open-source are done in C++ and there's a company called black duck that measures this kind of stuff they look at lots of open-source projects and try to figure out what programming language they are primarily written in and the most recent information this is from last month as I recall C++ is in second place it's the second most popular language for open source kind of good and if we look at the trend line so is this increasing or decreasing it turns out that the change in the last year is actually up two percent by comparison see is down 14% so it's increasing in popularity in open source if you believe these data so there's a lot of people use in the language which really does lead to the question why are these people using the language what is it about C++ that has made it successful for so long so I want to talk about the reasons why I think it is successful and I'm going to start with what I think is possibly the most important which is compatibility with C and I think people forget about the importance of compatibility with C first it's compatible with C programmers it continues to be really easy to take a C programmer and say listen you already know a subset of the language so all you need to do is start learning a few new things not everything at once maybe classes maybe inheritance maybe templates there's an awful lot of programmers who program and see and they already know the basics of C++ that was important in 1982 when the language was first started it continues to be important to gay because the longevity of C is truly amazing in fact if we go back and we look at the data that I showed you so C's been the number one or number two language for decades you'll notice that Java has now declined below C so C was the number one language for a while then it was number two and now it's back to number one and these data go back to the 1980s that's a really long time if you look at the data for which languages are most frequently used in open source projects in the last year the percentage that you see went down by 15% and it's still in the number one position by a lot so it was an important decision originally that C++ was compatible with C it continues to be important by the way this is also one of the reasons why I think C++ is likely to be a language which will be important in the future there's an enormous number of C programmers and for every one of them it is natural for them to consider moving into C++ so you've got a lot of people who basically already have an entree to the language it was important thirty years ago it's important now related to that is that C++ has source code that is as compatible with C as can be made the sort of the phrase that they used was as close to C as possible but no closer but the fact remains most C source code is also valid C++ source code that has a lot of advantages for example you can take an existing C library and if you need to recompile it with a C++ compiler if you need to get a compile a compatible binary that was true thirty years ago it's true now it's not as trivial now as it used to be but it's still an important feature it is compatible with the object code so it is really easy to go from C++ to C for some kind of very low-level manipulation that for some reason you can't do in C++ and one of the really nice things about C++ is you can link with C libraries so people have an investment in existing C code C++ can naturally take advantage of that that was important thirty years ago it continues to be important today when people are looking at programming languages sometimes they think that you know as long as the language is really good that's all that matters and programmers care about a lot about language but programmers care about other things too they care a lot about their editors for example and originally when you went with C++ you could say listen you can program using Emacs or VI or if there's some other editor you can use those too but you could use build chains coming from C you can use the linkers you could use the debuggers from C sadly I did program at a time when you had to use C debuggers in C++ it was not pleasant but it worked which was not something you could say for all the competing languages the relationship between C and C++ is so strong even now that in a lot of places people talk about c / c++ like it's one language which is kind of surprising because the C++ programmers look at c and go that is not my language and the C programmers go that is not my language but to the outside world you know it's all kind of the same thing and given the strong heritage and the strong linkage compatibility they you know they have a pretty close relationship so I think the first thing that's important about C++ and continues to be important is the compatibility with C I think another important thing that has led to C++ a success is a very general feature set so rather than building in specific features to solve particular problems they tended to solve more general problems interestingly what everyone's seems to agree on is that the single most important feature in C++ think for a moment in your head about what you would consider the single most important feature in C++ it has been there since the mid-1980s what do you think pardon me close curly brace okay so what did you say template metaprogramming yes that would be number one on the list so destructors single most important feature in the language probably destructors because destructors have led to the introduction of resource acquisition is initialization which is a general-purpose undo mechanism this is a language with a general-purpose undo mechanism it can undo memory allocations it can undo mutex acquisitions it can undo opening and clumb opening files it's a general-purpose undo mechanism it is the basis of general-purpose resource management in C++ other languages for example they have garbage collection which is great garbage collection collects one resource memory on the rest of the resources you're on your own C++ has one mechanism destructors for doing the terminus t'k finalization it is the existence of destructors which made it possible to do resource acquisition is initialization and that is what led to the ability to do the analysis to do exception safety requirements as far as I know mainstream exception handling analysis determining what is the basic exception safety guarantee what is the strong exception safety guarantee that all came from the C floss plus community and the foundation of that is destructors another general feature is templates now other languages had some sort of generics but templates were actually designed to be usable in ways that VR and I had not anticipated which certainly is what happened so we started with a generic programming like the template library that led to template metaprogramming and that led to some really interesting things that people were able to come up with as an example turns out that somewhere on planet Mars is a very nice little crater and the crater was caused by a spacecraft crashing in there it was called the Mars climate orbiter United States contributed a lot of money for it I believe Europe did as well and the reason we have a very expensive crater on the surface of Mars is because there were two pieces of software and one of them was using metric units and one of them was using English units spacecraft go boom because it turns out that pounds and Newtons are not the same thing through template metaprogramming it has been demonstrated that it is possible to do dimensional analysis checking during compilation the during compilation is what makes it interesting you can actually check to make sure there are no dimensional type errors during compilation which means it has absolutely no runtime cost no one thought we would be able to do that when templates were first introduced but templates are so general it's something which was able to be done this turns out to be more important than you might think there are a lot of people in the world who work in symbolic realms they're living in a realm where they say things like this I can't read that formula but there's physicists and mathematicians and statisticians lots of people who live in a symbolic world they're doing symbolic mathematics and eventually they come up with formulas and I say this is a formula - it could be important for our business this is something we want to have implemented in a way that runs quickly and usually that means it has to be translated into a programming language so the programming language might be C++ so this happens to be the C++ source code which I realize you can't read for this formula this happens to come from a research paper from some people at one of the national laboratories in the United States where they do some interesting work doing things like designing nuclear bombs it is important that if you are designing nuclear bombs that you design them correctly the price of failure in every measure is very large they test things really carefully I promise but what's interesting about it is that when you take a formula like this and you translate it into source code like that you'd like to make sure you haven't introduced any silly type unit errors by using template metaprogramming there are people at these research labs have developed mechanisms for making sure that before they start running their simulations of nuclear bombs and by the way that was the first place I ever ran into people who talked about CPU months they'd say well we'd run it for a few CPU months for an approximation of what we wanted to do I thought that was pretty good a CPU month but you want to make sure you don't run it for a few CPU months and then find out you made a silly unit error template metaprogramming lets you avoid that problem not a common language feature overloading another very general feature in C++ you can overload functions you can overload operators this is what give what gives rise to generic programming it is what gave rise to smart pointers which are an increasingly important role in C++ it gave us function objects the overloaded function call operator which most people think is odd the first time they hear about it well the overloaded function call operator is actually the basis for lambdas and lambdas are one of the most useful features in C++ 11 and C++ 14 but couldn't write them if you didn't have the basis in the first place which means that C++ in contrast to other programming languages is a language for library writers it's not really a language designed to say let's write applications it was designed from the beginning to say let's be able to write libraries the thinking was if we can write a good language for library development library writers will create great libraries for application development so it's a different way of thinking about what your programming language is used for so I think that's an important reason for C++ as success another important component is paradigm agnosticism at a time when some languages are we're a procedural or we are functional or at the time C++ was developed where object-oriented C++ says I'm all of those things so if you want procedural programming great you want free functions you've got free functions and in the 1980s this is at a time when everybody's that everything must be an object and C++ that functions are okay which is the basis of the standard template library the whole standard template library based on free functions a completely different idea it also meant you could naturally model symmetric relationships if if you can't put things outside classes then if you have a relationship between well I have a matrix class and I have a vector class and I want to be able to multiply matrices and vectors together which class does that belong in it actually goes to both of them and in other languages you have to choose one place or the other and in C++ you say no you just put it outside both of them it's gonna work fine it also means that after someone has defined a class and given it a bunch of member functions if someone comes along and says you know that's a useful class but I wish there were some additional functions that it had that's no problem now obviously if you can inherit from it to add if they want to but they don't have to inherit instead they can just say I'm gonna start writing some free functions which work on objects of those types and give me the functionality that I need which was sort of a radical idea but what I find interesting is that other languages have adopted the same idea for example c-sharp has something called extension methods which are essentially the same thing it's a way to add functionality without opening up the class D has something similar turns out they offer a little more syntactic sugar but the whole idea of you've got the class and then you've got other stuff related to it that was in C++ before other languages picked up on it and that has proven very successful we've got object-oriented programming I'll be a including multiple inheritance including six kinds of multiple inheritance but nevertheless including multiple inheritance we've got generic programming now the standard template library was authored by Alexander Stepanov Alexander Stepanov is not a fan of C++ and he really hates inheritance basically he doesn't like classes he doesn't really care for objects he doesn't really he thinks the whole thing is kind of nonsense yeah this is the man who wrote the standard template library but when you read his writings what he tells you is he had a vision for how he could write code that would work with any type and would be as efficient as if he hand tuned it for a particular type himself that was his vision and he said he tried to implement the standard template library in other languages if you if you go and you search online you'll find a number of places where he's exchanging debates basically with either people from lists for people from name your favorite language he goes look I tried in all those languages it just did not work C++ was the only language in which I could get it done which i think is a testimonial to the power of the template system and it was not that the template system was not designed to do that you got functional programming so we've got closures which it's not the best functional programming language in the world but it's moving in that direction but it also has template metaprogramming which is a purely functional programming language there is no assignment in template metaprogramming everything is a pure value it's immutable once it's been created it's a really ugly functional programming language but nevertheless it is a functional programming language you want to run with scissors you want to get hurt that's no problem if you want to do unsafe programming C++ can do it pointers casts unchecked arrays in the rationale for the C programming language there's a there's an official rationale for the standard for C at least for C 89 and one of the things it says is trust the programmer I'm not gonna put on you know when these safety features necessarily we're gonna trust that that that professional software developers know what they're talking about at the same time if you want to have safe programming you want vectors with bounds checking you want to have checked iterators to make sure that things work okay you can write those it's a language for library developers certainly one of the most important reasons why C++ has been successful is a fundamental commitment to systems programming I have said for many years that I believe C++ is the best lattice is a language best suited for what I call demanding systems applications demanding systems applications means that you've got a system you need to write and there's something about it that's particularly difficult there's a constraint you have to satisfy the constraint might be it has to be really fast the constraint might be it has to use minimal power the constraint might be I've got a data format that was designed by somebody programming in Fortran in the 1960s and we've lost the source code but we have to talk to it and I'm not making that up anybody here ever worked at a company or heard of working at a company where they had object code and they'd lost the source code okay there's a few people there I mean there are companies who go okay you have to link with this object file but we've lost the source code C++ says if that's what we need to do that's what we can do so if programs speed is important to you and there are some application areas where you can just not run fast enough simulations for example you can't run fast enough doing computer generation of images for video games for example you cannot run fast enough number crunching applications you typically can't run fast enough there's there's more applications than people think where speed is really important C++ has been very successful in those domains program size sometimes you really need to make sure that your footprint has been minimized either because that's got to be your working sets got to be as small as possible or it's got a into some really tiny embedded system C++ tends to give you control over that kind of stuff data layout data layout can be really important and maybe you've got a driver it's got to talk to the hardware and we've got you know bit three and bit 19 do weird things so I've got to talk to bit three and bit 19 funny hardware where if you want to turn something on you set the bit to zero weird stuff communications protocols working with legacy systems C++ says no problem you tell me what the format is you tell me what the rules are I can write the code to get that done this is the kind of stuff systems people deal with all the time you need to have a way to efficiently communicate with peripherals you need to be able to communicate with external systems operating systems you need to talk to other programming languages like C for example or anything that talks C C++ to walls does all that stuff and it's designed to do those things one of the languages fundamental hallmarks is the idea of zero overhead often you hear you don't pay for what you don't use which is a runtime comment you pay during compilation for everything but at runtime generally speaking if you're not using a language feature it costs you nothing something systems programmers really appreciate furthermore C++ is designed from the beginning for very wide platform availability microcontrollers to supercomputers this is one of the reasons by the way we don't have a fixed we don't say int SAR at least 32 bits or exactly 32 bits or something like that because if you're programming a microchip like that you know it may have an 8 bit compiler or only a 16 bit compiler there are no assumptions about i/o capabilities there aren't have any assumptions that you have an operating system CFO's does not require those kinds of support mechanisms and it's convenient to have but it's not required one of the results of that is you can find C++ compilers almost everywhere pretty much any kind of hardware you want to run someone's got a C++ compiler for it might be a really lousy C++ compiler but it's still a pretty reasonable way to write C++ code other programming languages if you're trying to do programming unusual digital signal processing chips or unusual video game consoles or some kind of special driver that's only found in certain kind of hardware you may not have any choice especially in recent years I think that it's emerged that one of the most important features in C++ is its dedication to backward compatibility one of the reasons C++ is as complicated today as it is is because we sort of said listen if you invested the time war from a company's point of view the money to build up an asset in C++ 20 years ago we will keep that code running if we possibly can source code written in let's say 1989 these days probably will still compiled under C++ 14 and it will do the same thing probably it's a few places where it might change but that's a fairly impressive record that we can go back 25 years let's say and say yeah the source code from 25 years ago that still works that still compiles that's important for companies which have very large investments in source code bases you don't want to have them gratuitously rewriting their source code all the time may not be a sexy reason but it's an important reason if we take a look at C++ and compare it to the vasa we can say well okay this is something even beyond a said for years after standardization started he says C++ has escaped the fate of the vasa it didn't kill over and disappear and certainly people have been predicting C++ was going to die for the last 20 years and I think the reasons why it hasn't died why it continues to do a very good job and be a very important programming language is because it's compatible with C it's got a very general feature set it doesn't take sides as regatta regards the particular programming paradigm you have to use and it has a commitment to systems programming and backward compatibility I want to talk a little bit more about this complexity thing because I hear people a lot complaining about complexity so this is what we talked about earlier that we have FX and it can meet all these different things which it certainly can how complicated is this I say I want to print out X anybody have trouble comprehending what that does the reason I'm asking is because the output operator is overloaded it is templatized and it is specialized in multiple scopes it has all the problems I mentioned earlier and yet in practice when you actually try to use it I think most programmers can figure out what's going on here tracing the code might be kind of a pain but it's not so complicated which is interesting because it means that although there is this potentially large amount of complexity in practice it doesn't arise as often as you might think if something's complicated it can be complicated for a couple of different people it can be complicated for users or it can be complicated for implementers so this is an example that the people who are in my class earlier today should be able to appreciate so if I say something like okay I want to move X into y pretty much everybody understands exactly what's going on with that maybe you need 15 seconds of explanation it's not a complicated thing that's the user view that's the user view of move now the implementer view of move is less pleasant so this is how move can be implemented and understanding exactly what's going on there takes a couple of hours of fairly intensive study but that's the library implementer for the person using the library not as complicated I think it's also worth noting that for the most part if people decide to use C++ my experience is they've usually already ruled out a bunch of other languages they've already decided look it really is a demanding systems application we can't get it written in some other language and if that's the case it sort of means there's a certain degree of self selection which is of the people coming to the language they've already got complicated problems so if you've got a complicated problem complicated problems often have complicated solutions the world is a dirty messy complicated place somehow those that dirtiness that complication is going to be reflected in the software and if you also have to run let's say as fast as possible or compatible with some data format defined by somebody else then C++ may be what you turn to which sort of implies that if you choose C++ you've already got complications so that could be a reason why C++ seems more complicated than other languages and then the people who use C++ are special I spend a lot of time talking to people about C plus I spent a lot of time explaining things and actually the last three days has been a really good example of this all sort of say okay here's a new feature so I'm talking about this new feature and what I want to do is I want to talk about the sweet spot where the feature works completely normally completely regular everything's exactly the way you would expect and the people in the in the class go yeah yeah yeah what I want to know is what happens right here on the boundary of the design space you know what happens if this is true and this is true and this is true and this is true and then go well okay what happens right here you know and then they'll go well okay what happens if I try to do something which is impossible what would happen if I did this impossible thing so it is entirely possible that one of the reasons that C++ is complicated is because you're all sick I I'm just raising it as a possibility there are some people who truly have a love affair with complexity this is a good language for those people so C++ is a language that is being changed for thirteen years it didn't 1998 to 2011 it did not change very much so in 1990 the arm the annotated reference manual first book on C++ that defined it 453 pages for the whole language and that included explanations 453 pages well so C++ 98 776 pages no explanations there 706 pages a 71% bigger took 8 years Cephas 11 took 13 years thirteen hundred and fifty-three fun-filled pages of text 75 percent bigger but you can sort of see you know we wait eight years we get this giant document we wait thirteen years we get this giant document c++ 14 only one percent bigger good news only about 20 pages longer but it only took three years C++ 17 only another three years probably gonna be a lot bigger than C++ 14 that's my expectation bigger is more complicated when you consider that in C++ we are largely committed to backward compatibility what that means is generally speaking nothing's gonna go out of the language there's a few things that get removed or deprecated but almost everything in the language today it's gonna stay there because that saves people's investment in legacy code which means we keep adding new stuff to a language which is already really big which means it's going to get more complicated it seems obvious you start with something that's big and complicated you make it bigger and yet I think we can say there is actually some simplification through added complexity so if we think about how we would do something on every element of a vector in C++ 98 you'd write a loop that looks something like this and you're typing stuff like I've got to create iterators and I've got to explicitly test and increment them a standard C++ 98 code it works we've all written it so in C++ 11 we can make it a lot easier if we want to deal with iterators we can just say Auto and C begin and suddenly it becomes a lot shorter a lot shorter but in many cases we can just use a range based for loop now this code here that was legal in C++ 98 it's still legal and these two things got added so the whole language got bigger but from a programmers perspective things got simpler which i think is a nice improvement if you think about function objects and how they got created so in C++ 98 let's suppose I would like to create a function object which will tell me whether something is between let's say 10 and 20 well if I wanted to do that in C++ 98 I would write code that looks like this that's a fair amount of code to have to say I want to check to see if it's between 10 and 20 in C++ 11 I can write a lambda expression takes two lines that seems like kind of a nice improvement now this code continues to be legal so the language got more complicated we just don't write code like that anymore so the old code keeps compiling the new stuff is simpler let us suppose what I would like to do is write some kind of a function this is C++ 11 and what I want to do is take some arguments and I want to be able to perform an operation in this case I want to validate credentials and then I want to afford those are forward those arguments to some other function so this is how you would do it in C++ 11 this is how you could do it in C++ 14 with polymorphic very attic template lambdas so C++ 14 makes all that turn into that so yeah the language is getting bigger so technically I mean this is why the specifications gonna probably break 1,500 pages but that doesn't mean that it's necessarily going to get more complicated it just means that the old stuff keeps working and the new stuff is going to start working as well so if we think about the fate of the vazha and compare it to the fate of c++ if you'd like to see the vazha as i said it didn't sail very far it was barely a used ship and they got it up off the bottom of the harbor they put it in a museum you can go and admire it in i think it's in stockholm and c++ on the other hand is a language that is being used all the time people are still working with it it's getting important work done and I think the reasons for its success are the ones that I have mentioned so any questions about my perspective on the success of C++ hmm so the question is what I think about its future for let's say 10 or 15 years purely from a pragmatic perspective there is such a large installed base of C++ this is going to be a really important industrial language for decades to come that would be even if nobody continued programming in it and a lot of people are continuing to programming in it so I think that it is going to be at least as important on an industrial basis as it has been it's probably never going to regain the cachet of being the sexy language that all the cool people are using on the other hand I think it's going to be used extensively in in demanding systems applications so for example there's the well-known example of Facebook was writing everything in PHP and they couldn't get enough servers and I couldn't get enough electricity to keep the systems running they wrote a PHP to C++ translator and they improved performance by some very large percentage I don't remember 40% 60% what's interesting about that is a friend of mine who you may have heard of Andre Alexandre skew has written some C++ books and he works at Facebook and and one of the things that he does is he works on improving performance and what he tells me is if you're at Facebook and you can get a 1% performance improvement it runs 1% faster for Facebook that saves the company millions of dollars per year so one percent equals millions of dollars now there's not a lot of companies like Facebook but there are a lot of companies there's enough companies that have large server farms that are doing lots of computation where these small increments can make a big difference so I think that in the realm of demanding systems applications C++ will continue to be very popular yeah hmm and I've heard that there is already some production code used in face book written indeed so my question is what's your opinion on the D language comparing with us okay I don't know D so I can't really comment on that which is sort of ironic because two weeks ago they asked me to give a keynote address at the D conference it turns out I was somewhat surprised to see this it turns out if you go to a conference for a programming language that is different from C++ and you say uncomplimentary things about C++ you're a big hit D is an interesting programming language I've read a book about it but I really I'm not a deep programmer what I will say is I talked to Andre about it because Andre is very interested in seeing the popularity of D increase he'd like to see more and more companies use it but one of the things that he told me is the hardest people to convince to use D are C++ programmers because if you if you go to the C++ programs and you sort of say here's this new language look at this feature look at this feature look at this feature and the problems that it lets you solve the C++ people go well I already know how to solve that I know how to do that well III can do that too which I find interesting because when I first started teaching people how to program in C++ a long time ago I was always teaching C programmers and when I would teach the C programmers and I'd say look let's talk about some really cool stuff you can do in C++ for example virtual functions I'd say isn't this great you can have a pointer to a base class we had pointers to base classes back then you had a pointer to a base class and you've got a bunch of derived classes you can create a container of pointers to base class you can call virtual functions in automatically calls the right function for the object that you're pointing to how cool is that and most C programmers were like that's cool but the really good C programmers the really good C programmers our goal what's the problem all you have to do is create a struct to put an array of function pointers inside it initialize setting where's the problem so these days from what I can tell the D programming language is not sort of targeting C++ programmers they're trying to establish a reputation on their own as being different from C++ as opposed to better than C++ and it will be interesting to see what happens to D but you know in theory it's a competitor to C++ but I think that right now that's not really what they're pushing pages pages do estimate it's good how many pages would how much of it is the good parts it's numb you know I mean most of it is good parts in this I mean because the thing is I mean a bad part to me would be this is something that you should never use or that has no reasonable application and there are a few things where I would say okay you should probably never use that or it's it's been replaced by a better way of doing things an example that I mentioned I mentioned in my talk earlier today for example bind standard mind is a useful part of the library a lot of people have used it I believe that yeah as of C++ 14 there is no reason to use bind so I would say bind you know really we could get rid of bind now we're never going to get rid of bind because there's a lot of legacy code that uses it but that would be an example of something that I think probably we could do without but everything in there probably does have an application almost everything at one time or another so I would say most of the stuff in there is good stuff I think it could probably be made better stuff in some cases but I think most of what's there is probably reasonable Oh is there any slightest chance that C++ in foreseeable future will get rid of C preprocessor or make it unnecessary like bind in my opinion no there there's a whole cottage industry of people who do preprocessor metaprogramming it's one of the biggest impediments to writing tools for C++ is dealing with the preprocessor because it's very extensively used I think that many people would like to get rid of it nobody likes it but it lets you do stuff you can't do in any other way so I think realistically speaking the chances of that going away in the foreseeable future very small they heard about helps other C++ ABI proposal and what you think how reported it for support last future which proposal library today oh the ABI prepared yeah all I know that herb has been working on proposing an ABI I think it's a very recent proposal I haven't read it myself and I have no idea what the chances of that being adopted are yes it's herb setter and I still have no idea what the chances are of it being adopted it's important not to put too much stock in personalities as an example as an example if you take if you call a sink I'm going to assume you all know everything so here we go if you take a sink you get a future from it then the shared state referred to the future referred to by the future from a sink causes your thread to block in its destructor most people agree this is a really bad idea herb hates it herb hates it so much he convinced the Microsoft compiler team not to implement it he was so sure that he'd be able to go to the standardization committee and say listen we've got to change this behavior so he wrote up a proposal he went to the standardization committee and the result was they didn't change anything and I believe the reason was that believe the reason was they said listen herb we agree with your arguments in general the problem is this has been published since C++ 2011 came out and now there's legacy code that depends on it and we do not want to break that legacy code so herb Sutter is a great guy he's gets a lot of stuff done he has a lot of weight on the sanitization committee but that does not mean he gets his way so he can come forth with an ABI and that's great and people might build on it but there's a lot of vendors you have to get on board to do something as big as that I'd love to see an ABI it's a great shortcoming in C++ that we don't have one but I think it's important to recognize that most standardization proposals are not adopted hello may I ask thank you may I ask a personal question about your career about your personal consultancy short words what's fun about it what's interesting how you became this of how I got to doing what I'm doing yes sure ask in in 1985 I got bored of working so I went into a ph.d program which is a great way to make no money but not be bored and when I was in the ph.d program in 1988 I was asked to be a teaching assistant in a class on software engineering where the professor said we're going to use C++ that is when I had to learn C++ so I learned C++ in 1988 and then about a year later someone came to me because there are various training companies in the world and if you're a corporate training company what you want to do is go to companies and say we have great trainers who can teach you new technology and then the companies go ooh we have money take some from us the problem for the training companies is that they need to find people who can go and teach for one week at a time who don't want to be employees who are experts in technology and good at teaching this is what graduate students were made for it's perfect match for graduate students so a professor came to me and said Scott how would you like to make more money in three days than you currently make in a month and I said I would like that so that led to my teaching C++ and at the time I would go for week-long hands-on courses to teach C++ to C programmers and I think most people now can't imagine what this must have been like because C++ was a very simple language compared to the way it is now but think of yourself as a poor C programmer you've never heard of classes you've never heard of constructors you've never heard of destructors you've never heard of default parameters you've never heard of override overloading you've never heard of inheritance you've never heard of virtual functions you've never heard of references and you can't figure out what they are and I would teach these courses and and by Friday these poor people were dying they said we're never going to understand this and so on Friday afternoon I say look look it's not that hard let's go to the whiteboard we're gonna write down what you really have to remember so if your class has a pointer make sure that you give it a copy constructor and an assignment operator if you got a base class make sure you give it a virtual destructor declare your data members private just just the basic stuff and after I had done that for a while somebody said you should write a book I said man I can write a book and then somebody else said you should write a book and at that time I was supposed to be working on my PhD dissertation I said I should write a book so because the book was easy and the PhD was hard so so so then I wrote the book and then things sort of picked up after that so there was no grand scheme it was an accident and then to sort of cap off the story this was 1991 and I remember my wife said to me she said you know how long are you gonna be able to do this c++ thing and i said you know it's a programming language it's a fad i give it five years maximum so it's doing okay so far so there you go you have said several quite a few nice things about c++ hmm can you say something nasty about c++ maybe about security I suppose I could you know that sort of falls in it for what it when it comes to security this falls into the realm of trust the programmer it's got pointers you can do anything you want it's not checked you know that vet cuts both ways if I were going to criticize C++ that is not what I would criticize I think that's I think that's part of the nature of being a systems programming language learn Java so when I'm learning plus plus I'm scared a little because this language is complicated and so is there okay I'm not a Java programmer either having said that I will say that one of the things about Java and some other managed languages is they have these giant selections of libraries so if you want to be able to do any kind of reasonably complicated task probably somebody has done it before and that means you often have a task of tracking down the appropriate library and then using the library I think that's a really useful skill I think the skill of saying I don't want to write this from scratch myself which is very much a C++ way of thinking but instead I'm gonna find some existing library and I'm gonna try to combine it with some other libraries to get the application up and running in a reasonable period of time I think that's a really useful skill so I think that would be a reasonable reason why you might learn Java I think also that it's useful to have used a managed programming language which has garbage collection and pointers that can move around underneath the hood and it doesn't even tell you got pointers I mean it's an interesting experience having said that and bearing in mind that I don't know Java again my friend Andre Alexandre skew one of his jobs is to go and recruit people to try and see if they have what it takes to program at Facebook which is a very demanding environment and when he goes any interviews students especially he would he tells me that one of his standard interview questions is he says what I want you to do is just he goes any programming language you want I don't care what I want you to do is show me how to implement a doubly-linked list even a singly linked list and what he told me so this is second hand but what he told me was the Java people have absolutely no idea how to approach that task he goes I'm just looking for someone to say something about a link and a node and a next pointer and the Java people in many cases would be like well you know there's a standard list class in the library you go well right but how would you implement it so the danger of focusing too much on Java I think is it keeps things at such a high level that you can avoid learning about some of the lower level stuff so if you choose to learn Java I think it has some some advantages but just don't get stuck in Java [Music] ok ok you know it's funny you mentioned Scala I went to one talk on Scala I'm pretty sure with Scala I went to one top so I know from 3 hours of lectures on Scala and what I remember about Scala was so good and remember I don't know Java so I'm sitting in a talk on the would-be successor to Java and I don't know Java and and I was talking about Scala and they go now remember in Java here you can't do blah blah blah blah so you can do this here and I go I've heard that argument before and then they go but that leads to this kind of problem I go I know where this is leading I've been there before so my reaction to Scala was that it's recreating the C++ experience in Java so if Scala is successful congratulations I have just presented your future to you in 40 minutes there are many features in boost which were integrated into C++ 1130 r1 and there are also many brand-new features in some special frameworks like UT where they have their own their own compiler and extension to the first post language do aware of any features that might be in from qt that may be incorporated in C++ than the nearest versions of Hospice and especially something about reflection I am not aware of any proposals coming from from the Qt community doesn't mean that they're not there but I haven't heard about them I should point out I'm not on the standardization committee I think of all the things I don't program I don't know Java I don't know D I'm not on the standardization committee I haven't heard anything about that so that doesn't mean that they don't exist what I do know is there are 13 study groups in the C++ standardization committee a study group is sort of a subcommittee that's looking into particular issues one of them is reflection for example one of the one of them is compiled looking at a compile-time reflection hello thank you for the talk and it looks like the real reason why support was did not sink is that the King of Sweden did not design it but seriously what is the process of language design and how is it determined what gets into the next standard of language for C++ for C++ it very much is designed by committee so I mean there is a standardization committee they vote on everything and this is one of the reasons why things are less cohesive than they might be one of the most common questions that people say is why don't they have feature XYZ in the language why isn't there better reflection or why aren't there more libraries and it turns out that in many cases the answer is because nobody proposed it so basically what you get out of the standardization committee what we all get out of the standardization committee is whatever this group of roughly 40 to a hundred people decide that they want to work on there is um there is no single person who oversees the whole thing be Arnaz on the committee he had his voice has a lot of weight he doesn't always get what he wants herbs voice has a lot of weight he doesn't always get what he wants so it's very much designed by committee why don't we take one more question and then is there pizza did you say I'm only asking out of intellectual interest what does the flavour to be true doesn't my favorite feature that Cephas doesn't have my I guess I would say it isn't so much a language feature I think that in 2014 it is embarrassing that we have a language that has no idea that the internet exists or that we have URLs so I would say the two things I really missed our number one there really should be a library for networking and for dealing with the internet and for stuff like that there's work being done on that but there's nothing right now so that I think is just this major gaping thing and the second thing is it'd be really nice to have some kind of simple graphics library of which they're also working on one of the reasons I mentioned this is it used to be I guess they still do it when you sell your books at Amazon Amazon has a sales rank so of course as an author let's just say you are interested in your sales rank and so I used to say that the author's hello world in any programming language was to write a program which would go to Amazon look up your sales rank and bring it back and plot it overtime on a graph and so in C++ you'd say great the first thing is I need to go to Amazon hmm and then if you figured that out it was like okay now I need to plot it on a graph hmm so to me those are the two it's really libraries that are missing more than language features so I don't know what the official protocol is but I can say my feet are tired so why don't we stop right now I'm gonna hang around for a while if you have additional questions thank you for coming [Applause] thank you you
Info
Channel: Christian Semmler
Views: 66,707
Rating: undefined out of 5
Keywords: c++, C++11, C++14, scott meyers, C++ and beyond, cppcon, herb sutter, gcc, microsoft, Bjarne Stroustrup (Author), effective C++, Vasa (Ship)
Id: ltCgzYcpFUI
Channel Id: undefined
Length: 67min 3sec (4023 seconds)
Published: Mon Jun 23 2014
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.