[MUSIC] Welcome. I'm professor Ira Pohl of the University of California, Santa Cruz and I'm gonna be your instructor for the next number of weeks, where we're going to do C++ for C program. I was going to explain a little bit about what the course was gonna do for you. The course is organized in two four week segments the first segment is going to take you through. The basics of C++. Today, we'll get through C++ as a better C or we even try to understand what better means. I'll also be assigning your homework today. And your first homework assignment, which will be due in a week, will be to convert some C code that'll be posted to C++ code. So you'll be able to do that right after our discussions today. The next two are graph theory programs. Now, I will explain these algorithms. One is the shortest path algorithm and the other is a minimum spanning tree algorithm. But I am expecting the people in this class to already have a year's experience both in programming in detail in C or an equivalent language. And roughly the background that you would get in a freshman/sophomore year of computer science. So there we would expect you to understand elementary data structures. Things like lists and stacks, and to have some of the basics in studying algorithms, including probably some of what we will be implementing. So for many of you this may be revisiting something you've already seen in your student days. But by the end of the first four weeks you should be proficient at a professional level in using the C++ language, if you already came in knowing C. Now for getting through the course work we're going to have quizzes that will be The end of some of my recorded segments and then there'll be one final. Okay, so let's start. What does it mean for one thing to be better than another thing? It's not really that simple an idea. Was Willie Mays better than Mickey Mantle? >> A night to remember. Candlestick park, San Francisco. May 5th, 1966. Paul Austeen pitched and there it went. The 512th home run of Willie's legendary career. >> In an epic seven game struggle, arch foes the Yankees and the Dodgers battle for the World Series crown. Mickey Mantle climaxed the season in which he won the triple batting crown When I was a kid growing up in New York, we had three great center fielders. >> Mays was the center fielder for the then New York Giants, Mantle for the New York Yankees, and people probably forget the third center fielder. He was Duke Snider. The Duke of Brooklyn. Now, arguably, Mays and Mantle are two of the greatest players who ever played, but All day long in the various bars and coffee houses in New York there would be the discussion. Would I rather have Mays or would I rather have Mantle? We also have ideas on food. You could use butter or you can use margarine in some contexts. They're frequently interchangeable. Which is better? What would that mean? And then finally, the question we're going to try to answer in the class, is C++ better? Is it better than, for example, Java? So, quiz. Why don't you see what you think? In what sense is margarine better than butter, or vice versa? Why don't you think about that and write in an answer. [MUSIC] So, here are some of the things you might have thought about. Calories. Well, roughly speaking, if you look it up mostly it's a tie. Margarines tend to be 35 calories. That may be surprising. They don't typically save you anything on butter. Some margarines are healthier. They have no fats, some margarines contain no cholesterol whereas butter is made from animal fat. So if there's a health factor and you have something like diabetes or heart disease in your background, it might even be prescribed by your doctor to have certain types of margarine. But, as we know, going to a nice French restaurant, it's gonna be butter. Butter is better. Chefs like butter. Butter has more vitamins. Bottom line, not an easy question, lot of context. Okay, so let's now return to our main subject, C+++. It originated with C, as we said earlier. Most of you have programmed in C or in an equivalent language for at least a year, and you are competent. That's an expectation in the class. C has a deep history. It's been around for quite a while. C, Traditional C, as you can see in this slide Was invented by Dennis Ritchie, and Dennis Ritchie was working with Ken Thompson. And they were working on something that most of you will know about, the Unix operating system. In fact, they both invented the Unix operating system and received the highest award that you can get as a computer scientist, namely the Turing Prize, for this work. So, they were a two person project at Bell Labs in 1972, and they were writing an operating system. And they had originally been writing it in a language called B, and B had come from another language called BCPL, and so on. Back to Algol, which is a foundational language invented in 1968 by an international group of computer scientists. As a standard for algorithmic languages and probably in some ways the most influential single language in the history of programming languages. Now, Dennis and Ken just had this language for their particular project. And we call such a language a system's implementation language. It wasn't really meant for wider use, it was meant almost as a personal language. And you'll see, or you'll know that there are many obscure things in C notation. Well, one of their guiding principles was type as little as possible. So the language was incredibly terse. It had many strange operators. Those operators conformed to the operating system and the architecture of Of the small microprocessor they were working on. It was a PDP. Now, that was such a successful project that people wanted to expand on it, and Brian Kernaghan, and Richie, then wrote up the language, and that's called KNRC, and that's one of the most influential programming books And again, in our profession. K&RC, which was fairly primitive, had relatively little type safety, morphed into something called ANSI C in the 80s. So as people expanded the use of C, especially professional use of C, There were standardization committees and there were major improvements made. ANSI C, which should up around 1985, remains in wide use. Later, the committees continued to meet, and there is a newer version of the standard. But I would say the bulk of C work still done in industry is basically the 1985 standard. And that 1985 standard is documented in Kernighan and Ritchie edition two, which many of you might have. So why go to C Plus Plus, where we have such a successful and important language? C Plus Plus was a language written by Bjarne Stroustrup and he was also at Bell Labs. Now Stroustrup had come from a tradition, in Denmark, of object-oriented programming. He had learned his programming in a language that was developed by Norwegian computer scientists Called Simulus, Simulus 67. And he just felt that was a better methodology. But that wasn't going to be supported at Bell Labs. If you wanted to do work at Bell Labs, you worked in C. It was okay to extend C. So there were many, what you might call pre-processors that added, extended A version of C with ideas from other communities. So there was for example a form of C that had a lot of concurrency [INAUDIBLE] and that concept's taken from Meta. So in that tradition invented something he called initially C with classes. And he added that on with a preprocessor. And it got very successful just like. And so it escaped its roots which was, in effect, this very vibrant basic research laboratory. Bell Labs at AT&T. And so Bell Labs decided it would support a industry product and allow Bjarne Stroustrup to ship and support C plus plus version one. And that was 1985. And the language developed much as the language like C developed, with support from industry and with ANSI standard committees, modifying the language, building it and improving it. And so by 1996, when there was a major ANSI standard The language grew to be fairly large. So C versus C++. C is small. C is primarily assistance implementation language. C++ is large. C supports imperative programming, sort of classical programming where you write little functions. And functions are the way. You compartmentalize your programs. And C++ is what you might call the Swiss army knife of programming. It has a tool for every occasion. So it also supports two very important forms of programming, object orientation Again, you might want to think Simula. And it supports something called generic programming, which I'm going to make a big deal about. So you probably won't have a lot of experience with generic programming, and that's one of the benefits that you're gonna learn in going over the material over the next few weeks. I would like you all to think about from what you know about C and C++ so far, very little, what might you think, Makes C++ better than C. After all, this is our first topic. So, A, it was invented later, so it comes up ten years later. B, Bjarne Stroustrup is a better language designer than Dennis Ritchie. They both were at Bell Labs. C, C++ has more features than C. D, simpler. What would be your choice? Give you a minute. Well, Programming languages. Some people think 68 was one of the best languages ever invented, and that's 60, excuse me. 68, another language that was a very elegant language. It's not always true that better comes later. Dennis and Bjarne are both excellent computer scientists. Dennis won the Turing prize, but he won it mostly for Unix. The answer I was expecting. What I would consider the best answer, is a sort of semi-logical answer. C is a subset of C plus plus and C plus plus has more in it and has better libraries. So if you want to think more as better, not everybody thinks more is better, but I That would be the general argument and it certainly is not best C plus plus is easier C plus plus is far harder. Even the components of the case would make a hard time learning C plus plus is C. A more interesting comparison is Java versus C++. Java shows up in 1995. Java is invented at Sun. The Sun people have great affinity for another OO language. Called Smalltalk. Smalltalk was the language invented at PARC, which is a very famous Xerox lab and among other things is the source of inspiration for the Mac. Lots of things connected with the personal computer, the graphical user interface. They all come from parc. So small talk, which was a pure object oriented language, inspired Java Which also has a C connection. It has C-like syntax, unlike Smalltalk. But C++ has this inherently imperative methodology, coming from C. System implementation language, low level. And Java is meant to be purely OO and high level. So the inventors, chiefly Gosling, the son, just felt that they could do better. Java has a JVM, a virtual machine. Java provides Universal Synaptics, so the old thematic thing was, write once, run everywhere. That's a good thing, and it's much less a development because you don't have to do everything individualized through the platform. C++ originally compiled to C. So C was this very efficient SIL and it had different compilers, depending on the platform, and indeed, had slightly different semantics depending on the platform. So it could be tuned to the platform. So it was frequently the most efficiently higher level language That existed on a platform. C++ wanted to maintain that advantage. So there's no hidden overhead. So one of the benefits for Java is you get garbage collection. You don't have to manage memory. Memory leaks go away, more or less. Whereas in C++ You have to have a sophisticated notion of memory and memory management. But you don't get a hit in run time costs. So you have a very interesting comparison between Java and C++ And that remains a raging argument in the programing language community.