[Script Info] Title: [Events] Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text Dialogue: 0,0:00:00.00,0:00:10.00,Default,,0000,0000,0000,, Dialogue: 0,0:00:10.00,0:00:11.00,Default,,0000,0000,0000,, Dialogue: 0,0:00:11.00,0:00:15.00,Default,,0000,0000,0000,,This presentation is delivered by the Stanford Center for Professional Dialogue: 0,0:00:15.00,0:00:25.00,Default,,0000,0000,0000,,Development. Dialogue: 0,0:00:25.00,0:00:29.00,Default,,0000,0000,0000,,I'm guessing by the fact that I can see myself that we're on. Dialogue: 0,0:00:29.00,0:00:33.00,Default,,0000,0000,0000,,Welcome back to CS106L. My name's Keith. I'm a section Dialogue: 0,0:00:33.00,0:00:37.00,Default,,0000,0000,0000,,leader here. I teach CS106L, which is the standard C++ program and Dialogue: 0,0:00:37.00,0:00:37.00,Default,,0000,0000,0000,,laboratory. Dialogue: 0,0:00:37.00,0:00:39.00,Default,,0000,0000,0000,,I recognize a few people here, which Dialogue: 0,0:00:39.00,0:00:40.00,Default,,0000,0000,0000,,is great. Dialogue: 0,0:00:40.00,0:00:44.00,Default,,0000,0000,0000,,Julie wanted me to come in today and talk to you about the C++ Dialogue: 0,0:00:44.00,0:00:47.00,Default,,0000,0000,0000,,programming language, what's it look like outside of CS106B? Dialogue: 0,0:00:47.00,0:00:50.00,Default,,0000,0000,0000,,What sorts of things do you need to be aware of to just kind of give you a general Dialogue: 0,0:00:50.00,0:00:53.00,Default,,0000,0000,0000,,picture of what this language looks like? Dialogue: 0,0:00:53.00,0:00:56.00,Default,,0000,0000,0000,,Before I get into the actual C++ stuff, I wanted to start off by Dialogue: 0,0:00:56.00,0:00:59.00,Default,,0000,0000,0000,,congratulating all of you for making it through this class. That's not a Dialogue: 0,0:00:59.00,0:01:01.00,Default,,0000,0000,0000,,small accomplishment. Dialogue: 0,0:01:01.00,0:01:04.00,Default,,0000,0000,0000,,If you think about when you started, day one, probably looking at this screen right here, probably Dialogue: 0,0:01:04.00,0:01:05.00,Default,,0000,0000,0000,,thinking, Dialogue: 0,0:01:05.00,0:01:08.00,Default,,0000,0000,0000,,what's that [inaudible], what's Genlib, what's C [inaudible], and why's it Dialogue: 0,0:01:08.00,0:01:11.00,Default,,0000,0000,0000,,really, really less than something? Dialogue: 0,0:01:11.00,0:01:12.00,Default,,0000,0000,0000,,Look where you are now. Dialogue: 0,0:01:12.00,0:01:16.00,Default,,0000,0000,0000,,You now know how to be a client of the vector, the stack, the map, the queue Dialogue: 0,0:01:16.00,0:01:17.00,Default,,0000,0000,0000,,and the set. Dialogue: 0,0:01:17.00,0:01:20.00,Default,,0000,0000,0000,,You know that recursion, you know pointers, you know Linklis and binary Dialogue: 0,0:01:20.00,0:01:21.00,Default,,0000,0000,0000,,[inaudible] and graphs. Dialogue: 0,0:01:21.00,0:01:25.00,Default,,0000,0000,0000,,You know algorithmic analysis and graph algorithms and searching and sorting. Dialogue: 0,0:01:25.00,0:01:26.00,Default,,0000,0000,0000,,You know how the lexicon works. Dialogue: 0,0:01:26.00,0:01:29.00,Default,,0000,0000,0000,,You know how to implement all of these classes. You know data abstraction. Dialogue: 0,0:01:29.00,0:01:34.00,Default,,0000,0000,0000,,That's not a small accomplishment. That's really something to be proud of. Dialogue: 0,0:01:34.00,0:01:37.00,Default,,0000,0000,0000,,What I wanted to say is that these are real, practical tools that will follow Dialogue: 0,0:01:37.00,0:01:39.00,Default,,0000,0000,0000,,you, no matter where you take them. Dialogue: 0,0:01:39.00,0:01:43.00,Default,,0000,0000,0000,,Some of you might go on in CS. You might think, wow, I really like this class. I want to Dialogue: 0,0:01:43.00,0:01:45.00,Default,,0000,0000,0000,,see where it goes. That's great. Dialogue: 0,0:01:45.00,0:01:48.00,Default,,0000,0000,0000,,No matter where you take it, if you go and take algorithms, you take Dialogue: 0,0:01:48.00,0:01:52.00,Default,,0000,0000,0000,,compliers or data bases or operating systems, the skills you've learned here is really Dialogue: 0,0:01:52.00,0:01:54.00,Default,,0000,0000,0000,,going to be the foundation Dialogue: 0,0:01:54.00,0:01:57.00,Default,,0000,0000,0000,,of all of your programing. You're always going to be using maps. You're always Dialogue: 0,0:01:57.00,0:02:00.00,Default,,0000,0000,0000,,going to be using vectors. You're going to need recursion, no matter where you Dialogue: 0,0:02:00.00,0:02:01.00,Default,,0000,0000,0000,,apply it. Dialogue: 0,0:02:01.00,0:02:04.00,Default,,0000,0000,0000,,It's really wonderful that you have these skills. Dialogue: 0,0:02:04.00,0:02:06.00,Default,,0000,0000,0000,,Of course, some of you aren't going to go on in computer science. That's totally fine. You Dialogue: 0,0:02:06.00,0:02:11.00,Default,,0000,0000,0000,,took this class and said, it's not for me or, you know, maybe not. Well, Dialogue: 0,0:02:11.00,0:02:12.00,Default,,0000,0000,0000,,that's fine too because Dialogue: 0,0:02:12.00,0:02:15.00,Default,,0000,0000,0000,,whether you go into sociology or philosophy or psychology or math or Dialogue: 0,0:02:15.00,0:02:16.00,Default,,0000,0000,0000,,physics or chemistry, Dialogue: 0,0:02:16.00,0:02:18.00,Default,,0000,0000,0000,,there are problems to be solved, Dialogue: 0,0:02:18.00,0:02:20.00,Default,,0000,0000,0000,,and there are problems you can solve with a computer. Dialogue: 0,0:02:20.00,0:02:23.00,Default,,0000,0000,0000,,What you've learned in this class is the most valuable skill of them all, which Dialogue: 0,0:02:23.00,0:02:25.00,Default,,0000,0000,0000,,is how to take a problem, Dialogue: 0,0:02:25.00,0:02:26.00,Default,,0000,0000,0000,,model it Dialogue: 0,0:02:26.00,0:02:27.00,Default,,0000,0000,0000,,and solve it. Dialogue: 0,0:02:27.00,0:02:29.00,Default,,0000,0000,0000,,That really is something. Dialogue: 0,0:02:29.00,0:02:32.00,Default,,0000,0000,0000,,The skills you've learned here transcend any specific programming language. Dialogue: 0,0:02:32.00,0:02:36.00,Default,,0000,0000,0000,,You can do everything you've done in here, in Java, in C++, in PHP, Dialogue: 0,0:02:36.00,0:02:41.00,Default,,0000,0000,0000,,in Python. Everything that you think of, you will be using these same tools. Dialogue: 0,0:02:41.00,0:02:42.00,Default,,0000,0000,0000,,That said, Dialogue: 0,0:02:42.00,0:02:46.00,Default,,0000,0000,0000,,we've taught you everything in this class using the C++ programming Dialogue: 0,0:02:46.00,0:02:46.00,Default,,0000,0000,0000,,language. Dialogue: 0,0:02:46.00,0:02:48.00,Default,,0000,0000,0000,,We use C++ Dialogue: 0,0:02:48.00,0:02:52.00,Default,,0000,0000,0000,,because it's very good for expressing the concepts that we were going over. It Dialogue: 0,0:02:52.00,0:02:56.00,Default,,0000,0000,0000,,has great support for recursion, has exposed pointers, so you can do things like Dialogue: 0,0:02:56.00,0:02:58.00,Default,,0000,0000,0000,,Linklis and binary trees quite nicely. Dialogue: 0,0:02:58.00,0:03:01.00,Default,,0000,0000,0000,,It has objects so you can do data abstraction. It's got templates. It's a very Dialogue: 0,0:03:01.00,0:03:05.00,Default,,0000,0000,0000,,good mix of different programing strategies and different programming styles Dialogue: 0,0:03:05.00,0:03:07.00,Default,,0000,0000,0000,,that means we can teach you things without having to bog you down in Dialogue: 0,0:03:07.00,0:03:09.00,Default,,0000,0000,0000,,language syntax. Dialogue: 0,0:03:09.00,0:03:11.00,Default,,0000,0000,0000,,That said, this really hasn't been much of a class Dialogue: 0,0:03:11.00,0:03:13.00,Default,,0000,0000,0000,,in C++. Dialogue: 0,0:03:13.00,0:03:16.00,Default,,0000,0000,0000,,Think of it was we all put you inside the C++ bus and drove Dialogue: 0,0:03:16.00,0:03:19.00,Default,,0000,0000,0000,,you up to the top of the mountain of CS106B knowledge. Dialogue: 0,0:03:19.00,0:03:21.00,Default,,0000,0000,0000,,You know that the bus got you up there, Dialogue: 0,0:03:21.00,0:03:24.00,Default,,0000,0000,0000,,but you don't really know what's going on under the hood. Dialogue: 0,0:03:24.00,0:03:27.00,Default,,0000,0000,0000,,That's okay because what you learn in this class is more important than that. Dialogue: 0,0:03:27.00,0:03:30.00,Default,,0000,0000,0000,,All the programing language and knowledge in the universe is not going to help you Dialogue: 0,0:03:30.00,0:03:33.00,Default,,0000,0000,0000,,solve a problem if you don't know how to use a vector, you don't know how to make a Dialogue: 0,0:03:33.00,0:03:36.00,Default,,0000,0000,0000,,map, and you can't make a recursive function solve things. Dialogue: 0,0:03:36.00,0:03:40.00,Default,,0000,0000,0000,,What I want to do today is talk about what the C++ language is. What's Dialogue: 0,0:03:40.00,0:03:42.00,Default,,0000,0000,0000,,it look like the real world? Dialogue: 0,0:03:42.00,0:03:43.00,Default,,0000,0000,0000,,What kind of stuff do you need to know? Dialogue: 0,0:03:43.00,0:03:46.00,Default,,0000,0000,0000,,More importantly, how do you take these skills that you've learned, which are very Dialogue: 0,0:03:46.00,0:03:50.00,Default,,0000,0000,0000,,generic, and go and apply them in this language. Dialogue: 0,0:03:50.00,0:03:53.00,Default,,0000,0000,0000,,I love C++. I've been using it for years. I think it's a beautiful Dialogue: 0,0:03:53.00,0:03:56.00,Default,,0000,0000,0000,,language. It's got support for so many different programing paradigms. It's Dialogue: 0,0:03:56.00,0:03:59.00,Default,,0000,0000,0000,,easy to use once you get a handle on it. Dialogue: 0,0:03:59.00,0:04:01.00,Default,,0000,0000,0000,,It lets you solve problems in so many different ways. Dialogue: 0,0:04:01.00,0:04:04.00,Default,,0000,0000,0000,,Really, I just want to show you what it looks like. Dialogue: 0,0:04:04.00,0:04:07.00,Default,,0000,0000,0000,,Think of this as an appetizer. I'm just going to give you the - this Dialogue: 0,0:04:07.00,0:04:10.00,Default,,0000,0000,0000,,is the C++ appetizer plate. I'll show you a little bit of this, a Dialogue: 0,0:04:10.00,0:04:11.00,Default,,0000,0000,0000,,little bit of that, Dialogue: 0,0:04:11.00,0:04:15.00,Default,,0000,0000,0000,,give you enough working knowledge that you know where to go to get help. Dialogue: 0,0:04:15.00,0:04:16.00,Default,,0000,0000,0000,,You can see Dialogue: 0,0:04:16.00,0:04:18.00,Default,,0000,0000,0000,,this is what you need to learn, get Dialogue: 0,0:04:18.00,0:04:21.00,Default,,0000,0000,0000,,an overview of what we've been doing, what we've provided you, what we haven't Dialogue: 0,0:04:21.00,0:04:22.00,Default,,0000,0000,0000,,provided you, Dialogue: 0,0:04:22.00,0:04:25.00,Default,,0000,0000,0000,,so that by the time you're done, you can think, Dialogue: 0,0:04:25.00,0:04:27.00,Default,,0000,0000,0000,,maybe I want to go on in this language. Dialogue: 0,0:04:27.00,0:04:30.00,Default,,0000,0000,0000,,I'm not going to force you to learn C++. I can't do that. I'm Dialogue: 0,0:04:30.00,0:04:33.00,Default,,0000,0000,0000,,not going to follow you around, did you learn C++ yet? Did you learn C++ yet? Dialogue: 0,0:04:33.00,0:04:35.00,Default,,0000,0000,0000,,No, I'm not going to do that. Dialogue: 0,0:04:35.00,0:04:38.00,Default,,0000,0000,0000,,You guys are all competent programmers right now. Dialogue: 0,0:04:38.00,0:04:41.00,Default,,0000,0000,0000,,You know how to solve these problems. You know how to take on these challenges. Dialogue: 0,0:04:41.00,0:04:43.00,Default,,0000,0000,0000,,So I just want to show you the language so you can decide whether or not you Dialogue: 0,0:04:43.00,0:04:44.00,Default,,0000,0000,0000,,want to pursue it. Dialogue: 0,0:04:44.00,0:04:47.00,Default,,0000,0000,0000,,Maybe you will. That'd be great. If not, Dialogue: 0,0:04:47.00,0:04:48.00,Default,,0000,0000,0000,,that's okay, too, Dialogue: 0,0:04:48.00,0:04:51.00,Default,,0000,0000,0000,,because you know how to tackle problems, and all you need now is a language to Dialogue: 0,0:04:51.00,0:04:53.00,Default,,0000,0000,0000,,do it Dialogue: 0,0:04:53.00,0:04:56.00,Default,,0000,0000,0000,,in. I want to show you basically four aspects of C++. First Dialogue: 0,0:04:56.00,0:05:00.00,Default,,0000,0000,0000,,some philosophy and some history because every language has a personality. Dialogue: 0,0:05:00.00,0:05:03.00,Default,,0000,0000,0000,,Every language wants to treat you as a programmer a different way, give you some Dialogue: 0,0:05:03.00,0:05:05.00,Default,,0000,0000,0000,,different options. So I just want to show you what to expect when Dialogue: 0,0:05:05.00,0:05:07.00,Default,,0000,0000,0000,,you're working with C++. Dialogue: 0,0:05:07.00,0:05:10.00,Default,,0000,0000,0000,,As a language, it has a lot of criticisms. How many of you have heard Dialogue: 0,0:05:10.00,0:05:15.00,Default,,0000,0000,0000,,bad things about C++ in any way, shape or form? Dialogue: 0,0:05:15.00,0:05:18.00,Default,,0000,0000,0000,,Wow, every, single person in this room, basically. Dialogue: 0,0:05:18.00,0:05:21.00,Default,,0000,0000,0000,,So there's a lot of criticisms leveled at this language, and what I want to Dialogue: 0,0:05:21.00,0:05:22.00,Default,,0000,0000,0000,,do Dialogue: 0,0:05:22.00,0:05:25.00,Default,,0000,0000,0000,,is show you what the mindset is so you can take a look at these Dialogue: 0,0:05:25.00,0:05:28.00,Default,,0000,0000,0000,,criticisms and evaluate them. In all seriousness, most of the Dialogue: 0,0:05:28.00,0:05:30.00,Default,,0000,0000,0000,,criticisms leveled at this language are Dialogue: 0,0:05:30.00,0:05:33.00,Default,,0000,0000,0000,,criticisms with things a language doesn't try to do. Dialogue: 0,0:05:33.00,0:05:37.00,Default,,0000,0000,0000,,At the same time, if you get this philosophy and you get this history, you'll Dialogue: 0,0:05:37.00,0:05:38.00,Default,,0000,0000,0000,,understand where this language came from, Dialogue: 0,0:05:38.00,0:05:41.00,Default,,0000,0000,0000,,what it's designed to do and where it's going. Dialogue: 0,0:05:41.00,0:05:44.00,Default,,0000,0000,0000,,The second thing I want to talk about is the actual mechanics. Dialogue: 0,0:05:44.00,0:05:47.00,Default,,0000,0000,0000,,What does the programing language look like? So I'll talk about the Dialogue: 0,0:05:47.00,0:05:47.00,Default,,0000,0000,0000,,libraries, and Dialogue: 0,0:05:47.00,0:05:49.00,Default,,0000,0000,0000,,I'll talk about the core language features. Dialogue: 0,0:05:49.00,0:05:52.00,Default,,0000,0000,0000,,What happens when you take away things like [inaudible] and Synfi? What are you going to have Dialogue: 0,0:05:52.00,0:05:54.00,Default,,0000,0000,0000,,to do now that you don't have those? In Dialogue: 0,0:05:54.00,0:05:58.00,Default,,0000,0000,0000,,terms of it's actually pretty straightforward and you already know most of it. Dialogue: 0,0:05:58.00,0:06:00.00,Default,,0000,0000,0000,,Then some language features that we didn't cover, things that you would expect to Dialogue: 0,0:06:00.00,0:06:02.00,Default,,0000,0000,0000,,see in a professional setting Dialogue: 0,0:06:02.00,0:06:05.00,Default,,0000,0000,0000,,that we didn't go over in this class because it's needlessly complicated and Dialogue: 0,0:06:05.00,0:06:08.00,Default,,0000,0000,0000,,doesn't have much to do with this general data structure and Dialogue: 0,0:06:08.00,0:06:10.00,Default,,0000,0000,0000,,algorithm challenges we've been giving you. Dialogue: 0,0:06:10.00,0:06:12.00,Default,,0000,0000,0000,,Finally, just some references. Dialogue: 0,0:06:12.00,0:06:14.00,Default,,0000,0000,0000,,Where do you go? Dialogue: 0,0:06:14.00,0:06:17.00,Default,,0000,0000,0000,,You want to learn C++? Great. We have a list of wonderful books and resources Dialogue: 0,0:06:17.00,0:06:18.00,Default,,0000,0000,0000,,you can go and reference, Dialogue: 0,0:06:18.00,0:06:20.00,Default,,0000,0000,0000,,and it can get you up to speed very quickly. Dialogue: 0,0:06:20.00,0:06:22.00,Default,,0000,0000,0000,,So it's kind of a game plan. Dialogue: 0,0:06:22.00,0:06:23.00,Default,,0000,0000,0000,,See what's out there, Dialogue: 0,0:06:23.00,0:06:28.00,Default,,0000,0000,0000,,have some fun with it and learn where to go. Sound good? Okay. Dialogue: 0,0:06:28.00,0:06:29.00,Default,,0000,0000,0000,,So I want to start off Dialogue: 0,0:06:29.00,0:06:32.00,Default,,0000,0000,0000,,with a quick history of C++. Dialogue: 0,0:06:32.00,0:06:34.00,Default,,0000,0000,0000,,So C++ did not come into being one day when a whole bunch of programmers came Dialogue: 0,0:06:34.00,0:06:37.00,Default,,0000,0000,0000,,into a room, made some demonic incantations over a bubbling cauldron and Dialogue: 0,0:06:37.00,0:06:39.00,Default,,0000,0000,0000,,walked out. It didn't happen. Dialogue: 0,0:06:39.00,0:06:42.00,Default,,0000,0000,0000,,It was not invented in one day. People did not sit down and say, our language is going to look like Dialogue: 0,0:06:42.00,0:06:44.00,Default,,0000,0000,0000,,this. Dialogue: 0,0:06:44.00,0:06:45.00,Default,,0000,0000,0000,,It has a history. Dialogue: 0,0:06:45.00,0:06:49.00,Default,,0000,0000,0000,,It has evolution, and you can see different traces of we tried doing Dialogue: 0,0:06:49.00,0:06:51.00,Default,,0000,0000,0000,,this. It didn't work. Dialogue: 0,0:06:51.00,0:06:54.00,Default,,0000,0000,0000,,Let's go add this feature, etc. Dialogue: 0,0:06:54.00,0:06:56.00,Default,,0000,0000,0000,,It started off Dialogue: 0,0:06:56.00,0:06:58.00,Default,,0000,0000,0000,,with this guy. Dialogue: 0,0:06:58.00,0:07:02.00,Default,,0000,0000,0000,,So I will attempt to pronounce his name. It's Bjarne Stroustrup. Dialogue: 0,0:07:02.00,0:07:05.00,Default,,0000,0000,0000,,I've been told that the way to pronounce this is to say Stroustrup with a Dialogue: 0,0:07:05.00,0:07:10.00,Default,,0000,0000,0000,,Norwegian accent while cramming a potato down your throat. I'll Dialogue: 0,0:07:10.00,0:07:10.00,Default,,0000,0000,0000,,just Dialogue: 0,0:07:10.00,0:07:14.00,Default,,0000,0000,0000,,get it close. Anyway, he's a Danish computer scientist, and he was getting his PhD in computer Dialogue: 0,0:07:14.00,0:07:15.00,Default,,0000,0000,0000,,science from Cambridge, Dialogue: 0,0:07:15.00,0:07:19.00,Default,,0000,0000,0000,,and his specialty was in distributive systems and operating systems. So his goal Dialogue: 0,0:07:19.00,0:07:22.00,Default,,0000,0000,0000,,was, let's take some problems, spread it out over several computers, have Dialogue: 0,0:07:22.00,0:07:26.00,Default,,0000,0000,0000,,them communicate via network protocol and get some results. Dialogue: 0,0:07:26.00,0:07:29.00,Default,,0000,0000,0000,,He chose to write this program in a language called Simula. I Dialogue: 0,0:07:29.00,0:07:34.00,Default,,0000,0000,0000,,confess, I don't know much about this language. I haven't heard anyone using it, but Dialogue: 0,0:07:34.00,0:07:37.00,Default,,0000,0000,0000,,back then, it was the his object-oriented language, and he said it helped him think Dialogue: 0,0:07:37.00,0:07:38.00,Default,,0000,0000,0000,,about the problem. Dialogue: 0,0:07:38.00,0:07:42.00,Default,,0000,0000,0000,,It had classes, so you could build a computer object, a protocol object, a Dialogue: 0,0:07:42.00,0:07:43.00,Default,,0000,0000,0000,,network object, Dialogue: 0,0:07:43.00,0:07:46.00,Default,,0000,0000,0000,,and they'd send messages to each other the same way that a Dialogue: 0,0:07:46.00,0:07:48.00,Default,,0000,0000,0000,,physical computer, a physical network Dialogue: 0,0:07:48.00,0:07:51.00,Default,,0000,0000,0000,,and a physical protocol would communicate with each other. He Dialogue: 0,0:07:51.00,0:07:54.00,Default,,0000,0000,0000,,got it working pretty fast and ran it, Dialogue: 0,0:07:54.00,0:07:57.00,Default,,0000,0000,0000,,and much to his surprise, he found out that it was so abysmally slow that he could get no Dialogue: 0,0:07:57.00,0:07:59.00,Default,,0000,0000,0000,,practical results out of it. The Dialogue: 0,0:07:59.00,0:08:01.00,Default,,0000,0000,0000,,question is what went wrong? Dialogue: 0,0:08:01.00,0:08:04.00,Default,,0000,0000,0000,,It wasn't his program. It was the Simula language implementation. Dialogue: 0,0:08:04.00,0:08:08.00,Default,,0000,0000,0000,,He actually ran a profiler on his code to figure out why it was going slowly. Dialogue: 0,0:08:08.00,0:08:10.00,Default,,0000,0000,0000,,80 percent of the time his program was running, it was going automatic Dialogue: 0,0:08:10.00,0:08:13.00,Default,,0000,0000,0000,,garbage collection, even though he was doing [inaudible] memory management. Dialogue: 0,0:08:13.00,0:08:14.00,Default,,0000,0000,0000,,So think about this. Dialogue: 0,0:08:14.00,0:08:17.00,Default,,0000,0000,0000,,You spend several weeks writing a program. Dialogue: 0,0:08:17.00,0:08:17.00,Default,,0000,0000,0000,,You run it, Dialogue: 0,0:08:17.00,0:08:20.00,Default,,0000,0000,0000,,and for every line of code you're writing, four lines of meaningless code Dialogue: 0,0:08:20.00,0:08:24.00,Default,,0000,0000,0000,,that someone else wrote are also executing. That's really slow. So Dialogue: 0,0:08:24.00,0:08:27.00,Default,,0000,0000,0000,,he had to change approaches. He went and rewrote this entire program in a Dialogue: 0,0:08:27.00,0:08:30.00,Default,,0000,0000,0000,,different language called BCPL, which is related to C and the B Dialogue: 0,0:08:30.00,0:08:33.00,Default,,0000,0000,0000,,programing language that came before C. Dialogue: 0,0:08:33.00,0:08:36.00,Default,,0000,0000,0000,,Of course, it's very low-level, it's very fast, but it didn't have these nice Dialogue: 0,0:08:36.00,0:08:37.00,Default,,0000,0000,0000,,high-level features in it. Dialogue: 0,0:08:37.00,0:08:39.00,Default,,0000,0000,0000,,He got it working, but it took a lot of time. Dialogue: 0,0:08:39.00,0:08:42.00,Default,,0000,0000,0000,,When it was done, he decided, I'm never going to tackle a Dialogue: 0,0:08:42.00,0:08:46.00,Default,,0000,0000,0000,,problem like this again until I have a proper tool for the job. He Dialogue: 0,0:08:46.00,0:08:49.00,Default,,0000,0000,0000,,ended up at AT&T Bell labs, which is the same place that the C programming language came Dialogue: 0,0:08:49.00,0:08:53.00,Default,,0000,0000,0000,,out of. In fact, he knew Kernighan and Ritchie, who invented that, Dialogue: 0,0:08:53.00,0:08:55.00,Default,,0000,0000,0000,,and came up with this language called C with classes. It was Dialogue: 0,0:08:55.00,0:08:58.00,Default,,0000,0000,0000,,a precursor to C++, and people loved it. Dialogue: 0,0:08:58.00,0:09:02.00,Default,,0000,0000,0000,,It combined the best features of Simula, which is this object-oriented design, Dialogue: 0,0:09:02.00,0:09:04.00,Default,,0000,0000,0000,,with the best features of C, which is the runtime efficiency. Dialogue: 0,0:09:04.00,0:09:06.00,Default,,0000,0000,0000,,It was something that was fast, Dialogue: 0,0:09:06.00,0:09:09.00,Default,,0000,0000,0000,,flexible and helped you think about problems. Dialogue: 0,0:09:09.00,0:09:11.00,Default,,0000,0000,0000,,What he would do is work on this implementation. Dialogue: 0,0:09:11.00,0:09:14.00,Default,,0000,0000,0000,,He had people actually using the C++, and when they needed new Dialogue: 0,0:09:14.00,0:09:15.00,Default,,0000,0000,0000,,features, they said, Dialogue: 0,0:09:15.00,0:09:17.00,Default,,0000,0000,0000,,Bjarne, it doesn't work. He'd go fix it. Dialogue: 0,0:09:17.00,0:09:20.00,Default,,0000,0000,0000,,We had this cycle of real programmers solving real problems Dialogue: 0,0:09:20.00,0:09:23.00,Default,,0000,0000,0000,,with this developer saying, okay, let's go fix it. Dialogue: 0,0:09:23.00,0:09:26.00,Default,,0000,0000,0000,,After a while, you ended up with C++. I think this Dialogue: 0,0:09:26.00,0:09:28.00,Default,,0000,0000,0000,,is the 25th anniversary of C++, so Dialogue: 0,0:09:28.00,0:09:30.00,Default,,0000,0000,0000,,how exciting. Dialogue: 0,0:09:30.00,0:09:33.00,Default,,0000,0000,0000,,I want to talk about the philosophy a little bit. What is really driving the Dialogue: 0,0:09:33.00,0:09:36.00,Default,,0000,0000,0000,,development of this language? What does it expect out of you? Dialogue: 0,0:09:36.00,0:09:39.00,Default,,0000,0000,0000,,So I have some quotes from this book called The Design and Evolution of C++. It's Dialogue: 0,0:09:39.00,0:09:40.00,Default,,0000,0000,0000,,a good book. You should read it. Dialogue: 0,0:09:40.00,0:09:42.00,Default,,0000,0000,0000,,The first one, Dialogue: 0,0:09:42.00,0:09:45.00,Default,,0000,0000,0000,,C++'s evolution should be driven by real problems, and you don't Dialogue: 0,0:09:45.00,0:09:47.00,Default,,0000,0000,0000,,want to get down on a quest for perfection. Dialogue: 0,0:09:47.00,0:09:51.00,Default,,0000,0000,0000,,Basically, this language is designed to solve real problems that Dialogue: 0,0:09:51.00,0:09:53.00,Default,,0000,0000,0000,,real programmers like you are going to run into Dialogue: 0,0:09:53.00,0:09:55.00,Default,,0000,0000,0000,,in not necessarily the best way. Dialogue: 0,0:09:55.00,0:09:56.00,Default,,0000,0000,0000,,It tries to do a good job. Dialogue: 0,0:09:56.00,0:10:01.00,Default,,0000,0000,0000,,It's not intended to be perfect. There are some sloppy edges, but it works. Dialogue: 0,0:10:01.00,0:10:04.00,Default,,0000,0000,0000,,Because it is driven by real problems and real design issues, you can solve Dialogue: 0,0:10:04.00,0:10:06.00,Default,,0000,0000,0000,,real problems with it. Dialogue: 0,0:10:06.00,0:10:07.00,Default,,0000,0000,0000,,If you think that's a good thing in a language, Dialogue: 0,0:10:07.00,0:10:11.00,Default,,0000,0000,0000,,I personally do. I think it's good to have a language that can solve problems, Dialogue: 0,0:10:11.00,0:10:14.00,Default,,0000,0000,0000,,then C++ is a good choice. Dialogue: 0,0:10:14.00,0:10:17.00,Default,,0000,0000,0000,,This is probably the one that you've seen the most. Don't try to force people. Dialogue: 0,0:10:17.00,0:10:21.00,Default,,0000,0000,0000,,C++ gives you so many choices that your question should not be, Dialogue: 0,0:10:21.00,0:10:24.00,Default,,0000,0000,0000,,how do I do this in the language, but more, which of these hundreds of Dialogue: 0,0:10:24.00,0:10:26.00,Default,,0000,0000,0000,,options is the best choice for me? Dialogue: 0,0:10:26.00,0:10:29.00,Default,,0000,0000,0000,,It really trusts you as a language. It will give you an incredible amount of Dialogue: 0,0:10:29.00,0:10:33.00,Default,,0000,0000,0000,,flexibility, even to the point where it will let you make the wrong decision. Dialogue: 0,0:10:33.00,0:10:36.00,Default,,0000,0000,0000,,I've always thought C++ is a language that will let you ride a Dialogue: 0,0:10:36.00,0:10:37.00,Default,,0000,0000,0000,,bicycle without a helmet Dialogue: 0,0:10:37.00,0:10:40.00,Default,,0000,0000,0000,,because that one time that you need to go under a bridge that's exactly a quarter inch over your Dialogue: 0,0:10:40.00,0:10:43.00,Default,,0000,0000,0000,,head, you wont have your helmet knock you off your bike. You Dialogue: 0,0:10:43.00,0:10:45.00,Default,,0000,0000,0000,,do have to worry about a lot of risks, Dialogue: 0,0:10:45.00,0:10:48.00,Default,,0000,0000,0000,,but in the end, you'll have more flexibility than you'll find in most other Dialogue: 0,0:10:48.00,0:10:50.00,Default,,0000,0000,0000,,languages you Dialogue: 0,0:10:50.00,0:10:52.00,Default,,0000,0000,0000,,see. Finally, I think the most important one Dialogue: 0,0:10:52.00,0:10:54.00,Default,,0000,0000,0000,,is this. Dialogue: 0,0:10:54.00,0:10:56.00,Default,,0000,0000,0000,,C++ makes programming more enjoyable Dialogue: 0,0:10:56.00,0:10:58.00,Default,,0000,0000,0000,,for serious programmers. Dialogue: 0,0:10:58.00,0:11:01.00,Default,,0000,0000,0000,,The two things here are serious programmers and more enjoyable. Dialogue: 0,0:11:01.00,0:11:04.00,Default,,0000,0000,0000,,This is a professional language. It's used in industry everywhere. Dialogue: 0,0:11:04.00,0:11:05.00,Default,,0000,0000,0000,,It's very fast. Dialogue: 0,0:11:05.00,0:11:08.00,Default,,0000,0000,0000,,It's very efficient. It has a bit of a learning curve. It is kind of Dialogue: 0,0:11:08.00,0:11:11.00,Default,,0000,0000,0000,,tricky to get into the language, but once you've got it, Dialogue: 0,0:11:11.00,0:11:13.00,Default,,0000,0000,0000,,the second part, the more enjoyable, is so true. Dialogue: 0,0:11:13.00,0:11:16.00,Default,,0000,0000,0000,,This language is fun to write things in. Dialogue: 0,0:11:16.00,0:11:19.00,Default,,0000,0000,0000,,Once you've got it down, you will actually step back from your program and say, wow, Dialogue: 0,0:11:19.00,0:11:22.00,Default,,0000,0000,0000,,I just wrote something that took every, single word out of this set that I had Dialogue: 0,0:11:22.00,0:11:24.00,Default,,0000,0000,0000,,[inaudible] contains a specific letter Dialogue: 0,0:11:24.00,0:11:25.00,Default,,0000,0000,0000,,in a single line of code. Dialogue: 0,0:11:25.00,0:11:29.00,Default,,0000,0000,0000,,Or I lettered all the contents of this file into my set in one line of code. Or I Dialogue: 0,0:11:29.00,0:11:31.00,Default,,0000,0000,0000,,just wrote a template that Dialogue: 0,0:11:31.00,0:11:34.00,Default,,0000,0000,0000,,is a multi-dimensional ray of any dimension I want. Dialogue: 0,0:11:34.00,0:11:37.00,Default,,0000,0000,0000,,Those are not trivial accomplishments, and you can do it with Dialogue: 0,0:11:37.00,0:11:38.00,Default,,0000,0000,0000,,this language. Dialogue: 0,0:11:38.00,0:11:39.00,Default,,0000,0000,0000,,It's fun. Dialogue: 0,0:11:39.00,0:11:41.00,Default,,0000,0000,0000,,It's a great language, and if you think that this sort of philosophy is what you Dialogue: 0,0:11:41.00,0:11:43.00,Default,,0000,0000,0000,,want, where it will trust you, Dialogue: 0,0:11:43.00,0:11:46.00,Default,,0000,0000,0000,,it will really let you make the decisions rather than forcing you into any one Dialogue: 0,0:11:46.00,0:11:47.00,Default,,0000,0000,0000,,paradigm, Dialogue: 0,0:11:47.00,0:11:48.00,Default,,0000,0000,0000,,learn C++. Dialogue: 0,0:11:48.00,0:11:51.00,Default,,0000,0000,0000,,I think you'll love it. So Dialogue: 0,0:11:51.00,0:11:55.00,Default,,0000,0000,0000,,philosophy. There's lots of it, but I'm not here to teach a philosophy Dialogue: 0,0:11:55.00,0:11:58.00,Default,,0000,0000,0000,,class. I'm here to teach you about C++, so let's get down to some of the details. What does this Dialogue: 0,0:11:58.00,0:12:00.00,Default,,0000,0000,0000,,language look like? Dialogue: 0,0:12:00.00,0:12:02.00,Default,,0000,0000,0000,,The first thing I want to do is talk about Dialogue: 0,0:12:02.00,0:12:04.00,Default,,0000,0000,0000,,what Genlib.H has. Dialogue: 0,0:12:04.00,0:12:06.00,Default,,0000,0000,0000,,Since day one, you probably have seen Dialogue: 0,0:12:06.00,0:12:07.00,Default,,0000,0000,0000,,things like this. How Dialogue: 0,0:12:07.00,0:12:10.00,Default,,0000,0000,0000,,to include Genlib. Very first line, right here. Dialogue: 0,0:12:10.00,0:12:14.00,Default,,0000,0000,0000,,What is in this Genlib thing? Has anybody actually looked at Genlib before? Actually, pulled up Dialogue: 0,0:12:14.00,0:12:20.00,Default,,0000,0000,0000,,the Genlib file and looked inside? No one? Okay. Dialogue: 0,0:12:20.00,0:12:22.00,Default,,0000,0000,0000,,If you look inside Genlib, Dialogue: 0,0:12:22.00,0:12:24.00,Default,,0000,0000,0000,,it looks mostly like this. Dialogue: 0,0:12:24.00,0:12:27.00,Default,,0000,0000,0000,,There are basically three important lines you need to know. Dialogue: 0,0:12:27.00,0:12:28.00,Default,,0000,0000,0000,,Time includes string. Dialogue: 0,0:12:28.00,0:12:31.00,Default,,0000,0000,0000,,So we talked to you about the string classes that was a built-in type, like Ent or Dialogue: 0,0:12:31.00,0:12:35.00,Default,,0000,0000,0000,,double. It's a class. It's like any other object, like a vector or a map. You do need Dialogue: 0,0:12:35.00,0:12:36.00,Default,,0000,0000,0000,,to pound include it. Dialogue: 0,0:12:36.00,0:12:39.00,Default,,0000,0000,0000,,We just took care of it for you because since you use it everywhere and it's easy to Dialogue: 0,0:12:39.00,0:12:42.00,Default,,0000,0000,0000,,forget and you can get some pretty nasty compiler errors if you don't, Dialogue: 0,0:12:42.00,0:12:44.00,Default,,0000,0000,0000,,we thought, Dialogue: 0,0:12:44.00,0:12:47.00,Default,,0000,0000,0000,,we'll be nice. We'll do that for you. Dialogue: 0,0:12:47.00,0:12:48.00,Default,,0000,0000,0000,,The second thing is this error function. Dialogue: 0,0:12:48.00,0:12:52.00,Default,,0000,0000,0000,,You've seen error. Genlib just gives you a prototype for it. The end. Dialogue: 0,0:12:52.00,0:12:56.00,Default,,0000,0000,0000,,But this last one right here using name space STD. Using the standard Dialogue: 0,0:12:56.00,0:12:58.00,Default,,0000,0000,0000,,name space. What on Dialogue: 0,0:12:58.00,0:13:00.00,Default,,0000,0000,0000,,earth is this line? Dialogue: 0,0:13:00.00,0:13:03.00,Default,,0000,0000,0000,,It looks almost like an English sentence. Dialogue: 0,0:13:03.00,0:13:05.00,Default,,0000,0000,0000,,Compiler, make my code work. Dialogue: 0,0:13:05.00,0:13:07.00,Default,,0000,0000,0000,,What's going on here? Dialogue: 0,0:13:07.00,0:13:10.00,Default,,0000,0000,0000,,Well, I'll show you. Dialogue: 0,0:13:10.00,0:13:14.00,Default,,0000,0000,0000,,Suppose I have this little program back here. Can anybody see this? So I want to pound include [inaudible] Dialogue: 0,0:13:14.00,0:13:17.00,Default,,0000,0000,0000,,and pound include string. Dialogue: 0,0:13:17.00,0:13:19.00,Default,,0000,0000,0000,,If you notice here, I don't have Genlib, and I'm going to make Dialogue: 0,0:13:19.00,0:13:22.00,Default,,0000,0000,0000,,a string and print it out. Dialogue: 0,0:13:22.00,0:13:26.00,Default,,0000,0000,0000,,So the question is, when I say string, my string, Dialogue: 0,0:13:26.00,0:13:28.00,Default,,0000,0000,0000,,what am I referring to? Dialogue: 0,0:13:28.00,0:13:31.00,Default,,0000,0000,0000,,Well, when this happens, the compiler says, well, go look for something called Dialogue: 0,0:13:31.00,0:13:32.00,Default,,0000,0000,0000,,string. Dialogue: 0,0:13:32.00,0:13:34.00,Default,,0000,0000,0000,,When we pound included string, Dialogue: 0,0:13:34.00,0:13:38.00,Default,,0000,0000,0000,,it put it inside this big bucket of something called name space standard. Dialogue: 0,0:13:38.00,0:13:41.00,Default,,0000,0000,0000,,The idea is that the real name of string is standard string. The real name of C out Dialogue: 0,0:13:41.00,0:13:44.00,Default,,0000,0000,0000,,is standard C out. The real name of endal is standard endal. Dialogue: 0,0:13:44.00,0:13:47.00,Default,,0000,0000,0000,,It's just so that if you make your own versions of those things, it doesn't have Dialogue: 0,0:13:47.00,0:13:51.00,Default,,0000,0000,0000,,the same name as the standard. It won't conflict, and your program will still compile. Dialogue: 0,0:13:51.00,0:13:54.00,Default,,0000,0000,0000,,But the problem is that if you try to run this, what Dialogue: 0,0:13:54.00,0:13:55.00,Default,,0000,0000,0000,,will happen is that Dialogue: 0,0:13:55.00,0:13:56.00,Default,,0000,0000,0000,,the compiler says string, Dialogue: 0,0:13:56.00,0:13:59.00,Default,,0000,0000,0000,,looks up here and hits this wall. It Dialogue: 0,0:13:59.00,0:14:03.00,Default,,0000,0000,0000,,says, oops, that's inside the standard name space. I can't go in there, Dialogue: 0,0:14:03.00,0:14:06.00,Default,,0000,0000,0000,,and you'll get this really nasty compiler error, something like, string's not defined. C out's not defined. Dialogue: 0,0:14:06.00,0:14:08.00,Default,,0000,0000,0000,,Endal's not defined. Dialogue: 0,0:14:08.00,0:14:12.00,Default,,0000,0000,0000,,Now, most of the time when you're programming, you want things like C out and Dialogue: 0,0:14:12.00,0:14:14.00,Default,,0000,0000,0000,,string to actually exist. Dialogue: 0,0:14:14.00,0:14:17.00,Default,,0000,0000,0000,,So rather than saying you have to call it standard string, standard C out, standard Dialogue: 0,0:14:17.00,0:14:19.00,Default,,0000,0000,0000,,endal, Dialogue: 0,0:14:19.00,0:14:22.00,Default,,0000,0000,0000,,you can introduce this little phrase right here, Dialogue: 0,0:14:22.00,0:14:24.00,Default,,0000,0000,0000,,using name space standard. What it says Dialogue: 0,0:14:24.00,0:14:26.00,Default,,0000,0000,0000,,is take this wall and get rid of it. Dialogue: 0,0:14:26.00,0:14:29.00,Default,,0000,0000,0000,,It's like, Mr. Compiler, tear down this wall, Dialogue: 0,0:14:29.00,0:14:30.00,Default,,0000,0000,0000,,and the result Dialogue: 0,0:14:30.00,0:14:34.00,Default,,0000,0000,0000,,is that this barrier gets a little bit Dialogue: 0,0:14:34.00,0:14:34.00,Default,,0000,0000,0000,,transparent. Dialogue: 0,0:14:34.00,0:14:38.00,Default,,0000,0000,0000,,It's all still included inside of the standard name Dialogue: 0,0:14:38.00,0:14:39.00,Default,,0000,0000,0000,,space, but now it's accessible. Dialogue: 0,0:14:39.00,0:14:42.00,Default,,0000,0000,0000,,So when you go, string goes, oh, yeah, that thing, and Dialogue: 0,0:14:42.00,0:14:44.00,Default,,0000,0000,0000,,actually compiles. Dialogue: 0,0:14:44.00,0:14:46.00,Default,,0000,0000,0000,,Now most of today, I'm not going to be hitting you with C++ and saying, Dialogue: 0,0:14:46.00,0:14:49.00,Default,,0000,0000,0000,,you must know this. You must know this. There's just not enough time to Dialogue: 0,0:14:49.00,0:14:50.00,Default,,0000,0000,0000,,go over everything, Dialogue: 0,0:14:50.00,0:14:53.00,Default,,0000,0000,0000,,but this little line might be something worth committing to memory because it's Dialogue: 0,0:14:53.00,0:14:56.00,Default,,0000,0000,0000,,the most noticeable change you'll see when you stop using Genlib. Dialogue: 0,0:14:56.00,0:14:59.00,Default,,0000,0000,0000,,If you don't put that line in your code, you'll get lots of compiler errors, and it will Dialogue: 0,0:14:59.00,0:15:00.00,Default,,0000,0000,0000,,just scare you. Dialogue: 0,0:15:00.00,0:15:02.00,Default,,0000,0000,0000,,So if you put this line in, Dialogue: 0,0:15:02.00,0:15:06.00,Default,,0000,0000,0000,,I'd say 90 percent of your compiler problems will go away. Dialogue: 0,0:15:06.00,0:15:07.00,Default,,0000,0000,0000,,That's that line. Dialogue: 0,0:15:07.00,0:15:10.00,Default,,0000,0000,0000,,That's Genlib, and if you want to take a look, Dialogue: 0,0:15:10.00,0:15:13.00,Default,,0000,0000,0000,,if you right this code, you basically replace all of Dialogue: 0,0:15:13.00,0:15:16.00,Default,,0000,0000,0000,,Genlib. The first header file you'll have to include is this one, CSTDLIB, the C Dialogue: 0,0:15:16.00,0:15:18.00,Default,,0000,0000,0000,,standard library. Dialogue: 0,0:15:18.00,0:15:22.00,Default,,0000,0000,0000,,I'm thinking that when the invented the C programing language, it cost them Dialogue: 0,0:15:22.00,0:15:26.00,Default,,0000,0000,0000,,several million dollars per consonant or vowel they put in their header files. Dialogue: 0,0:15:26.00,0:15:30.00,Default,,0000,0000,0000,,So they put it as small as possible but still readable. The idea Dialogue: 0,0:15:30.00,0:15:32.00,Default,,0000,0000,0000,,is that you have these two lines. Dialogue: 0,0:15:32.00,0:15:33.00,Default,,0000,0000,0000,,Pound include string Dialogue: 0,0:15:33.00,0:15:35.00,Default,,0000,0000,0000,,using the standard name Dialogue: 0,0:15:35.00,0:15:38.00,Default,,0000,0000,0000,,space. Then right here in this error function, you just Dialogue: 0,0:15:38.00,0:15:41.00,Default,,0000,0000,0000,,print everything to C error, which is like C out. It's just designed for error Dialogue: 0,0:15:41.00,0:15:45.00,Default,,0000,0000,0000,,handling. You call exit minus one, which says, quit this program. Report some error to Dialogue: 0,0:15:45.00,0:15:49.00,Default,,0000,0000,0000,,the operating system and we're done. Dialogue: 0,0:15:49.00,0:15:52.00,Default,,0000,0000,0000,,This is it. This is all that is contained in Genlib, and Dialogue: 0,0:15:52.00,0:15:54.00,Default,,0000,0000,0000,,the only two important lines are these two right here. Dialogue: 0,0:15:54.00,0:15:57.00,Default,,0000,0000,0000,,Including the string class and using the standard name space. If you do Dialogue: 0,0:15:57.00,0:15:58.00,Default,,0000,0000,0000,,that, Dialogue: 0,0:15:58.00,0:16:00.00,Default,,0000,0000,0000,,and you get [inaudible] Genlib, Dialogue: 0,0:16:00.00,0:16:03.00,Default,,0000,0000,0000,,you're going to be in perfectly good shape. Dialogue: 0,0:16:03.00,0:16:06.00,Default,,0000,0000,0000,,Now, Genlib is probably one of the easier ones, but what about some of these other Dialogue: 0,0:16:06.00,0:16:08.00,Default,,0000,0000,0000,,headers you've seen? Dialogue: 0,0:16:08.00,0:16:11.00,Default,,0000,0000,0000,,I could go into some detail about all of these, but I don't have Dialogue: 0,0:16:11.00,0:16:14.00,Default,,0000,0000,0000,,time. I really wish I could show you how these work, Dialogue: 0,0:16:14.00,0:16:17.00,Default,,0000,0000,0000,,but I'm going to give you a quick overview today Dialogue: 0,0:16:17.00,0:16:19.00,Default,,0000,0000,0000,,to show you what you'll need to know if you want to get off these Dialogue: 0,0:16:19.00,0:16:21.00,Default,,0000,0000,0000,,libraries. Dialogue: 0,0:16:21.00,0:16:25.00,Default,,0000,0000,0000,,The first one is [inaudible]. This is the one that gives you string to integer, Dialogue: 0,0:16:25.00,0:16:30.00,Default,,0000,0000,0000,,integer to string, string to reel, convert to uppercase, convert to lowercase, etc. Dialogue: 0,0:16:30.00,0:16:32.00,Default,,0000,0000,0000,,Behind the scenes, most of this stuff is backed by this class called a string stream. You've seen Dialogue: 0,0:16:32.00,0:16:33.00,Default,,0000,0000,0000,,[inaudible] Dialogue: 0,0:16:33.00,0:16:37.00,Default,,0000,0000,0000,,streams, you've seen - they're all streams. You can do Dialogue: 0,0:16:37.00,0:16:39.00,Default,,0000,0000,0000,,less than, you can do greater than. Dialogue: 0,0:16:39.00,0:16:42.00,Default,,0000,0000,0000,,The point of the string stream, it does the same thing, except that Dialogue: 0,0:16:42.00,0:16:44.00,Default,,0000,0000,0000,,it writes to a string buffer. Dialogue: 0,0:16:44.00,0:16:48.00,Default,,0000,0000,0000,,So you can take some integer, dump it into a string, that's your integer to Dialogue: 0,0:16:48.00,0:16:49.00,Default,,0000,0000,0000,,string function right there. Dialogue: 0,0:16:49.00,0:16:52.00,Default,,0000,0000,0000,,There's a couple other things you can do with it. We use it for doing Dialogue: 0,0:16:52.00,0:16:52.00,Default,,0000,0000,0000,, Dialogue: 0,0:16:52.00,0:16:56.00,Default,,0000,0000,0000,,conversion between strings in other data types like integers. Dialogue: 0,0:16:56.00,0:16:59.00,Default,,0000,0000,0000,,So you might want to look into that if you want to play around with it. Dialogue: 0,0:16:59.00,0:17:01.00,Default,,0000,0000,0000,,As for convert to upper or lower case, Dialogue: 0,0:17:01.00,0:17:04.00,Default,,0000,0000,0000,,there are these functions, two upper and two lower, that take individual characters Dialogue: 0,0:17:04.00,0:17:07.00,Default,,0000,0000,0000,,and convert them to upper or lower case. Just Dialogue: 0,0:17:07.00,0:17:10.00,Default,,0000,0000,0000,,fore loop over your string. Call that function every time. Dialogue: 0,0:17:10.00,0:17:13.00,Default,,0000,0000,0000,,Presto. Your string is in uppercase. That was pretty straightforward. Dialogue: 0,0:17:13.00,0:17:16.00,Default,,0000,0000,0000,,If you're interested, in CS106L, we actually wrote some of these Dialogue: 0,0:17:16.00,0:17:20.00,Default,,0000,0000,0000,,functions. If you want to have a working implementation of [inaudible], if you go to Dialogue: 0,0:17:20.00,0:17:24.00,Default,,0000,0000,0000,,the CS106L web site, under the code section, there is a working implementation Dialogue: 0,0:17:24.00,0:17:26.00,Default,,0000,0000,0000,,there. So if you want to keep using these things, Dialogue: 0,0:17:26.00,0:17:28.00,Default,,0000,0000,0000,,just go download that file, take a look at it, Dialogue: 0,0:17:28.00,0:17:31.00,Default,,0000,0000,0000,,play around with it, and it should work. Dialogue: 0,0:17:31.00,0:17:32.00,Default,,0000,0000,0000,,So Dialogue: 0,0:17:32.00,0:17:34.00,Default,,0000,0000,0000,,if you wanted to set up a Dialogue: 0,0:17:34.00,0:17:36.00,Default,,0000,0000,0000,,coding environment on some Dialogue: 0,0:17:36.00,0:17:38.00,Default,,0000,0000,0000,,Linux machine that Dialogue: 0,0:17:38.00,0:17:41.00,Default,,0000,0000,0000,,doesn't have any of the standard PC or Mac startup files, Dialogue: 0,0:17:41.00,0:17:46.00,Default,,0000,0000,0000,,we can just use that? Yeah, it uses only standard C++, so it will compile everywhere. Dialogue: 0,0:17:46.00,0:17:49.00,Default,,0000,0000,0000,,It works pretty well. I think we only defined a few of them, but you Dialogue: 0,0:17:49.00,0:17:51.00,Default,,0000,0000,0000,,can see how they work, and you can define it for Dialogue: 0,0:17:51.00,0:17:55.00,Default,,0000,0000,0000,,- you can do string to integer, string to double or string to reel pretty easily just be changing a Dialogue: 0,0:17:55.00,0:18:00.00,Default,,0000,0000,0000,,couple types around. Okay. Dialogue: 0,0:18:00.00,0:18:03.00,Default,,0000,0000,0000,,This is probably the big one you're going to miss. Sympio.H. Dialogue: 0,0:18:03.00,0:18:09.00,Default,,0000,0000,0000,,How many of you have ever played around with raw C++ input functions before? Dialogue: 0,0:18:09.00,0:18:12.00,Default,,0000,0000,0000,,They're kind of nasty. I've always thought this thing called C in, which Dialogue: 0,0:18:12.00,0:18:15.00,Default,,0000,0000,0000,,is the counterpart of C out that does input, is kind of like a rose. It's Dialogue: 0,0:18:15.00,0:18:19.00,Default,,0000,0000,0000,,very sweet. It's very delicate, but the second you break it, it stabs you with a thorn, Dialogue: 0,0:18:19.00,0:18:22.00,Default,,0000,0000,0000,,and it hurts a lot. Dialogue: 0,0:18:22.00,0:18:25.00,Default,,0000,0000,0000,,Really, you have to think of this as probably one of the most powerful one of Dialogue: 0,0:18:25.00,0:18:29.00,Default,,0000,0000,0000,,the hardest-to-use input libraries out of any programing language you'll see. Dialogue: 0,0:18:29.00,0:18:32.00,Default,,0000,0000,0000,,We gave you this Sympio library just to take care of all these things for you so Dialogue: 0,0:18:32.00,0:18:34.00,Default,,0000,0000,0000,,you don't have to worry about Dialogue: 0,0:18:34.00,0:18:36.00,Default,,0000,0000,0000,,it. Dialogue: 0,0:18:36.00,0:18:39.00,Default,,0000,0000,0000,,Everybody remember get line? You can use it to get a line out of a file? Dialogue: 0,0:18:39.00,0:18:43.00,Default,,0000,0000,0000,,You can use get line on this C in stream to do input reading. Dialogue: 0,0:18:43.00,0:18:44.00,Default,,0000,0000,0000,,Real line as text Dialogue: 0,0:18:44.00,0:18:46.00,Default,,0000,0000,0000,,uses string stream to convert it to an integer, Dialogue: 0,0:18:46.00,0:18:49.00,Default,,0000,0000,0000,,plus or minus a couple extra things. That's get integer. Dialogue: 0,0:18:49.00,0:18:52.00,Default,,0000,0000,0000,,Again, if you go to the CS106L web site, there is a working implementation of Dialogue: 0,0:18:52.00,0:18:53.00,Default,,0000,0000,0000,,this. Dialogue: 0,0:18:53.00,0:18:56.00,Default,,0000,0000,0000,,If you do want to consider doing C++ beyond this, it actually is Dialogue: 0,0:18:56.00,0:19:00.00,Default,,0000,0000,0000,,a pretty good set of input functions. You'd be surprised how many people don't Dialogue: 0,0:19:00.00,0:19:01.00,Default,,0000,0000,0000,,actually know how to write these things. Dialogue: 0,0:19:01.00,0:19:04.00,Default,,0000,0000,0000,,Go fire it up. Have some fun, Dialogue: 0,0:19:04.00,0:19:05.00,Default,,0000,0000,0000,,see what they do and Dialogue: 0,0:19:05.00,0:19:07.00,Default,,0000,0000,0000,,that way, you continue using the coding conventions that you've seen Dialogue: 0,0:19:07.00,0:19:12.00,Default,,0000,0000,0000,,but by only using standard C++. What about Dialogue: 0,0:19:12.00,0:19:14.00,Default,,0000,0000,0000,,random? Dialogue: 0,0:19:14.00,0:19:17.00,Default,,0000,0000,0000,,The random functions in C++ are Dialogue: 0,0:19:17.00,0:19:21.00,Default,,0000,0000,0000,,pretty simple. There's two functions, rand and Crand. Dialogue: 0,0:19:21.00,0:19:23.00,Default,,0000,0000,0000,,Random and C, the randomizer. Again, Dialogue: 0,0:19:23.00,0:19:27.00,Default,,0000,0000,0000,,consonants are expensive, vowels are expensive. Dialogue: 0,0:19:27.00,0:19:30.00,Default,,0000,0000,0000,,Rand gives you random integers in the range zero Dialogue: 0,0:19:30.00,0:19:31.00,Default,,0000,0000,0000,,to rand max. Dialogue: 0,0:19:31.00,0:19:34.00,Default,,0000,0000,0000,,So if you want to get a random double, you want to get a random integer, a random Goulian, Dialogue: 0,0:19:34.00,0:19:39.00,Default,,0000,0000,0000,,just take the number in that range, scale it down to zero one, scale it back up, translate it, Dialogue: 0,0:19:39.00,0:19:40.00,Default,,0000,0000,0000,,etc. Dialogue: 0,0:19:40.00,0:19:42.00,Default,,0000,0000,0000,,It turns out that this is probably the easiest one to rewrite from scratch. You just have to Dialogue: 0,0:19:42.00,0:19:46.00,Default,,0000,0000,0000,,be a little bit careful of how you do our bounce checking, but it's not so bad. Dialogue: 0,0:19:46.00,0:19:49.00,Default,,0000,0000,0000,,The header file for that is C standard library, but you can probably build Dialogue: 0,0:19:49.00,0:19:53.00,Default,,0000,0000,0000,,this one up from scratch pretty simply. Dialogue: 0,0:19:53.00,0:19:56.00,Default,,0000,0000,0000,,The one that you actually are going to be missing is this one. Dialogue: 0,0:19:56.00,0:19:58.00,Default,,0000,0000,0000,,Graphics.H and extended graphics. Dialogue: 0,0:19:58.00,0:20:02.00,Default,,0000,0000,0000,,Unfortunately, C++ does not have a standard graphics library. It Dialogue: 0,0:20:02.00,0:20:05.00,Default,,0000,0000,0000,,just doesn't exist. There's a couple reasons. One, it's very hard to Dialogue: 0,0:20:05.00,0:20:08.00,Default,,0000,0000,0000,,standardize graphics. You have to make sure that it's something that works on every, Dialogue: 0,0:20:08.00,0:20:10.00,Default,,0000,0000,0000,,single platform, which is very hard to do. Dialogue: 0,0:20:10.00,0:20:13.00,Default,,0000,0000,0000,,Also, if you're writing C++ code from a microprocessor where Dialogue: 0,0:20:13.00,0:20:16.00,Default,,0000,0000,0000,,you don't have graphics, it would be difficult to support the Dialogue: 0,0:20:16.00,0:20:18.00,Default,,0000,0000,0000,,library. Dialogue: 0,0:20:18.00,0:20:21.00,Default,,0000,0000,0000,,So there's no standard C++ equivalent, but I bet you this program Dialogue: 0,0:20:21.00,0:20:24.00,Default,,0000,0000,0000,,that I'm using right now is written in C++. It's got some kind of Dialogue: 0,0:20:24.00,0:20:25.00,Default,,0000,0000,0000,,graphics. Dialogue: 0,0:20:25.00,0:20:27.00,Default,,0000,0000,0000,,Most of this is from third-party libraries. I do Dialogue: 0,0:20:27.00,0:20:29.00,Default,,0000,0000,0000,,some Windows programing, so I use - for the Win32 API, which does some Dialogue: 0,0:20:29.00,0:20:31.00,Default,,0000,0000,0000,,graphics stuff. Dialogue: 0,0:20:31.00,0:20:35.00,Default,,0000,0000,0000,,There's a bunch of cross-platform ones like open GL. You can do X Window system. Dialogue: 0,0:20:35.00,0:20:36.00,Default,,0000,0000,0000,,I think Mac's is called Carbon. I Dialogue: 0,0:20:36.00,0:20:38.00,Default,,0000,0000,0000,,might be wrong about that. Dialogue: 0,0:20:38.00,0:20:41.00,Default,,0000,0000,0000,,[Crosstalk] Yeah, Dialogue: 0,0:20:41.00,0:20:44.00,Default,,0000,0000,0000,,there's a lot, and you won't have trouble finding it. You just won't Dialogue: 0,0:20:44.00,0:20:47.00,Default,,0000,0000,0000,,have a standard library that does it for you. So shop around with this. The Dialogue: 0,0:20:47.00,0:20:48.00,Default,,0000,0000,0000,, Dialogue: 0,0:20:48.00,0:20:50.00,Default,,0000,0000,0000,,ones we give you are pretty nice. Dialogue: 0,0:20:50.00,0:20:53.00,Default,,0000,0000,0000,,I might tell you how they work except that I don't know because it's Dialogue: 0,0:20:53.00,0:20:55.00,Default,,0000,0000,0000,,really, really hard. Dialogue: 0,0:20:55.00,0:21:00.00,Default,,0000,0000,0000,,So take a look around, and you'll find some ones that are quite nice. Dialogue: 0,0:21:00.00,0:21:02.00,Default,,0000,0000,0000,,Everything I've shown you up to this point are simple, like Dialogue: 0,0:21:02.00,0:21:03.00,Default,,0000,0000,0000,,how to read input, Dialogue: 0,0:21:03.00,0:21:04.00,Default,,0000,0000,0000,,how to convert to a string, Dialogue: 0,0:21:04.00,0:21:07.00,Default,,0000,0000,0000,,things that, while they're nice and important, are not going to Dialogue: 0,0:21:07.00,0:21:08.00,Default,,0000,0000,0000,,make or break your program. Dialogue: 0,0:21:08.00,0:21:11.00,Default,,0000,0000,0000,,The thing that is going to make a difference are Dialogue: 0,0:21:11.00,0:21:12.00,Default,,0000,0000,0000,,these ADTs. Dialogue: 0,0:21:12.00,0:21:14.00,Default,,0000,0000,0000,,The vector, the set, the map, Dialogue: 0,0:21:14.00,0:21:15.00,Default,,0000,0000,0000,,the stack, the queue. Dialogue: 0,0:21:15.00,0:21:16.00,Default,,0000,0000,0000,,Those are important. Dialogue: 0,0:21:16.00,0:21:17.00,Default,,0000,0000,0000,,If you don't have a map, Dialogue: 0,0:21:17.00,0:21:20.00,Default,,0000,0000,0000,,the number of things you can do in a program drops exponentially. Dialogue: 0,0:21:20.00,0:21:24.00,Default,,0000,0000,0000,,It's really impressive how much you need these data structures. Dialogue: 0,0:21:24.00,0:21:27.00,Default,,0000,0000,0000,,The good news is that C++ not only has a very good support for these data Dialogue: 0,0:21:27.00,0:21:31.00,Default,,0000,0000,0000,,structures, it has probably the best library in any standard programming Dialogue: 0,0:21:31.00,0:21:32.00,Default,,0000,0000,0000,,language Dialogue: 0,0:21:32.00,0:21:33.00,Default,,0000,0000,0000,,that does these things for you. Dialogue: 0,0:21:33.00,0:21:37.00,Default,,0000,0000,0000,,It's called the Standard Template Library, which is the Dialogue: 0,0:21:37.00,0:21:41.00,Default,,0000,0000,0000,,STL. For every, single container class you have seen in this class, all the ADTs, Dialogue: 0,0:21:41.00,0:21:42.00,Default,,0000,0000,0000,,you will find them in the STL. Dialogue: 0,0:21:42.00,0:21:46.00,Default,,0000,0000,0000,,The names might be a little bit different, the syntax is a little bit weirder, but conceptually, Dialogue: 0,0:21:46.00,0:21:49.00,Default,,0000,0000,0000,,it's the same thing. A vector is a vector, no matter what language Dialogue: 0,0:21:49.00,0:21:51.00,Default,,0000,0000,0000,,you write it Dialogue: 0,0:21:51.00,0:21:54.00,Default,,0000,0000,0000,,in. The STL Dialogue: 0,0:21:54.00,0:21:57.00,Default,,0000,0000,0000,,on top of that gives you these things called algorithms. Dialogue: 0,0:21:57.00,0:22:00.00,Default,,0000,0000,0000,,I'll talk about this in a little bit. Dialogue: 0,0:22:00.00,0:22:02.00,Default,,0000,0000,0000,,Basically, it's the best thing since sliced bread. Dialogue: 0,0:22:02.00,0:22:06.00,Default,,0000,0000,0000,,I'm not kidding. It's really wonderful and amazing, and I'll talk about that in a Dialogue: 0,0:22:06.00,0:22:07.00,Default,,0000,0000,0000,,little bit. Dialogue: 0,0:22:07.00,0:22:10.00,Default,,0000,0000,0000,,The STL is one of the major features of the C++ standard library. Dialogue: 0,0:22:10.00,0:22:11.00,Default,,0000,0000,0000,,It's Dialogue: 0,0:22:11.00,0:22:12.00,Default,,0000,0000,0000,,brilliantly designed. Dialogue: 0,0:22:12.00,0:22:13.00,Default,,0000,0000,0000,,It's not necessarily Dialogue: 0,0:22:13.00,0:22:17.00,Default,,0000,0000,0000,,the most intuitive thing, but once you get a handle of it, it's very Dialogue: 0,0:22:17.00,0:22:20.00,Default,,0000,0000,0000,,powerful. Dialogue: 0,0:22:20.00,0:22:23.00,Default,,0000,0000,0000,,The way you can visualize what this looks like is as this Dialogue: 0,0:22:23.00,0:22:25.00,Default,,0000,0000,0000,,somewhat pyramid Dialogue: 0,0:22:25.00,0:22:25.00,Default,,0000,0000,0000,,structure. Dialogue: 0,0:22:25.00,0:22:27.00,Default,,0000,0000,0000,,At the very bottom, you've got containers. Dialogue: 0,0:22:27.00,0:22:31.00,Default,,0000,0000,0000,,Your data structures, this is your vector, you map, your set. Dialogue: 0,0:22:31.00,0:22:33.00,Default,,0000,0000,0000,,You have iterators on top of that. You've all seen iterators in this class. Dialogue: 0,0:22:33.00,0:22:36.00,Default,,0000,0000,0000,,You've seen map and set iterators. Dialogue: 0,0:22:36.00,0:22:37.00,Default,,0000,0000,0000,,The STL is basically Dialogue: 0,0:22:37.00,0:22:41.00,Default,,0000,0000,0000,,all about iterators. Every, single container class has Dialogue: 0,0:22:41.00,0:22:42.00,Default,,0000,0000,0000,,iterators. Dialogue: 0,0:22:42.00,0:22:45.00,Default,,0000,0000,0000,,You can iterate over a vector or map or set. Dialogue: 0,0:22:45.00,0:22:46.00,Default,,0000,0000,0000,,Those worked Dialogue: 0,0:22:46.00,0:22:49.00,Default,,0000,0000,0000,,to build these things called algorithms where they're Dialogue: 0,0:22:49.00,0:22:51.00,Default,,0000,0000,0000,,functions that operate on ranges of data. Dialogue: 0,0:22:51.00,0:22:54.00,Default,,0000,0000,0000,,It's really impressive what you can do with these things. I'll show you a Dialogue: 0,0:22:54.00,0:22:57.00,Default,,0000,0000,0000,,little bit of that Dialogue: 0,0:22:57.00,0:23:01.00,Default,,0000,0000,0000,,later. These container classes, the good news is that the names are pretty similar. Dialogue: 0,0:23:01.00,0:23:04.00,Default,,0000,0000,0000,,Basically, take the 106 version, make it lowercase, you've got your Dialogue: 0,0:23:04.00,0:23:08.00,Default,,0000,0000,0000,,STL. So big vector turns into little vector. Big map turns into little map, Dialogue: 0,0:23:08.00,0:23:13.00,Default,,0000,0000,0000,,etc. One exception is grid. There is no STL grid class. It's very easy to Dialogue: 0,0:23:13.00,0:23:16.00,Default,,0000,0000,0000,,make one. All you have to do is take a vector and do some math to wrap Dialogue: 0,0:23:16.00,0:23:20.00,Default,,0000,0000,0000,,a two-dimensional container into a one-dimensional one. In fact, that's how our Dialogue: 0,0:23:20.00,0:23:22.00,Default,,0000,0000,0000,,grid works, so you'll have to build that one. Dialogue: 0,0:23:22.00,0:23:25.00,Default,,0000,0000,0000,,Otherwise, everything's taken care for you, and that's nice. Dialogue: 0,0:23:25.00,0:23:28.00,Default,,0000,0000,0000,,Again, they have the same fundamental abstractions. You know how to work with a Dialogue: 0,0:23:28.00,0:23:33.00,Default,,0000,0000,0000,,stack, so you know how to use the STL stack with a little extra syntax. Dialogue: 0,0:23:33.00,0:23:34.00,Default,,0000,0000,0000,,The big thing I will say up front, Dialogue: 0,0:23:34.00,0:23:36.00,Default,,0000,0000,0000,,the emphasis in the STL Dialogue: 0,0:23:36.00,0:23:37.00,Default,,0000,0000,0000,,is on speed. Dialogue: 0,0:23:37.00,0:23:40.00,Default,,0000,0000,0000,,In fact, they are designed to be really, really fast. Dialogue: 0,0:23:40.00,0:23:45.00,Default,,0000,0000,0000,,That means their notion of safety is, good one. Dialogue: 0,0:23:45.00,0:23:48.00,Default,,0000,0000,0000,,So what this means is you'll have to do your own bounce checking. Dialogue: 0,0:23:48.00,0:23:50.00,Default,,0000,0000,0000,,When you're iterating, you'll have to make sure you don't walk off the edge of your Dialogue: 0,0:23:50.00,0:23:51.00,Default,,0000,0000,0000,,container Dialogue: 0,0:23:51.00,0:23:52.00,Default,,0000,0000,0000,,and stuff like that. Dialogue: 0,0:23:52.00,0:23:56.00,Default,,0000,0000,0000,,One of the major reasons we didn't go over the STL in this class Dialogue: 0,0:23:56.00,0:23:57.00,Default,,0000,0000,0000,,is that, Dialogue: 0,0:23:57.00,0:24:00.00,Default,,0000,0000,0000,,which is if you're trying to figure out how to work with a vector, it's Dialogue: 0,0:24:00.00,0:24:03.00,Default,,0000,0000,0000,,really bad if you also have to worry about doing your own bounce checking. Dialogue: 0,0:24:03.00,0:24:05.00,Default,,0000,0000,0000,,If you're working with a map and you have to use the STL map, Dialogue: 0,0:24:05.00,0:24:07.00,Default,,0000,0000,0000,,you probably wouldn't ever want to use another map Dialogue: 0,0:24:07.00,0:24:09.00,Default,,0000,0000,0000,,for the rest of your life. It's pretty complicated. Dialogue: 0,0:24:09.00,0:24:12.00,Default,,0000,0000,0000,,The point is this is what you'll see in the professional environment because it's a very good library, and it's very Dialogue: 0,0:24:12.00,0:24:16.00,Default,,0000,0000,0000,,fast. Dialogue: 0,0:24:16.00,0:24:19.00,Default,,0000,0000,0000,,I want to give you a quick example of what this might look like. Dialogue: 0,0:24:19.00,0:24:22.00,Default,,0000,0000,0000,,This is a program I've written using the CS106 vector. I want to go Dialogue: 0,0:24:22.00,0:24:24.00,Default,,0000,0000,0000,,change it to use the STL to show you Dialogue: 0,0:24:24.00,0:24:28.00,Default,,0000,0000,0000,,it's the same thing with a little bit different syntax. Dialogue: 0,0:24:28.00,0:24:32.00,Default,,0000,0000,0000,,The first thing you have to do is say, the Specter.H we gave you, so you have Dialogue: 0,0:24:32.00,0:24:33.00,Default,,0000,0000,0000,,to change that to the standard vector, Dialogue: 0,0:24:33.00,0:24:36.00,Default,,0000,0000,0000,,which is vector in brackets. Dialogue: 0,0:24:36.00,0:24:40.00,Default,,0000,0000,0000,,Number of characters we have changed so far. Three characters. Dialogue: 0,0:24:40.00,0:24:44.00,Default,,0000,0000,0000,,Next thing, the big vector becomes little vector. Four characters. Dialogue: 0,0:24:44.00,0:24:48.00,Default,,0000,0000,0000,,The only big difference is this add function. Anyone who isn't in Dialogue: 0,0:24:48.00,0:24:50.00,Default,,0000,0000,0000,,my class want to guess Dialogue: 0,0:24:50.00,0:24:54.00,Default,,0000,0000,0000,,what you would call the function to append something to the end of a vector? Anyone Dialogue: 0,0:24:54.00,0:24:57.00,Default,,0000,0000,0000,,want to take a guess? [Inaudible]. Dialogue: 0,0:24:57.00,0:24:58.00,Default,,0000,0000,0000,,Append? That would Dialogue: 0,0:24:58.00,0:25:02.00,Default,,0000,0000,0000,,be nice. It's actually called push back. Dialogue: 0,0:25:02.00,0:25:05.00,Default,,0000,0000,0000,,There's good reason for this. It means all these different containers Dialogue: 0,0:25:05.00,0:25:08.00,Default,,0000,0000,0000,,have similar function names. Push back, Dialogue: 0,0:25:08.00,0:25:09.00,Default,,0000,0000,0000,,append, potato, Dialogue: 0,0:25:09.00,0:25:12.00,Default,,0000,0000,0000,,potato. Dialogue: 0,0:25:12.00,0:25:15.00,Default,,0000,0000,0000,,Okay. That's probably about ten or eleven character changes. Then Dialogue: 0,0:25:15.00,0:25:16.00,Default,,0000,0000,0000,,to loop over the thing, Dialogue: 0,0:25:16.00,0:25:18.00,Default,,0000,0000,0000,,it's exactly what you've seen before. Dialogue: 0,0:25:18.00,0:25:19.00,Default,,0000,0000,0000,,There is a size function. Dialogue: 0,0:25:19.00,0:25:23.00,Default,,0000,0000,0000,,There are brackets. You can go and iterate. You can go and access things. Dialogue: 0,0:25:23.00,0:25:26.00,Default,,0000,0000,0000,,The result, as you can see, is not that different. Dialogue: 0,0:25:26.00,0:25:28.00,Default,,0000,0000,0000,,There are a couple subtleties that I didn't go into here about how the Dialogue: 0,0:25:28.00,0:25:32.00,Default,,0000,0000,0000,,STL behaves different from the vector you've seen, but overall, it Dialogue: 0,0:25:32.00,0:25:36.00,Default,,0000,0000,0000,,is the same container. Dialogue: 0,0:25:36.00,0:25:39.00,Default,,0000,0000,0000,,The other one I want to call your attention to is the STL map. Dialogue: 0,0:25:39.00,0:25:42.00,Default,,0000,0000,0000,,So if you work with the STL, you need to know two containers, and the rest Dialogue: 0,0:25:42.00,0:25:44.00,Default,,0000,0000,0000,,follow from there. If you know vector and you know map, Dialogue: 0,0:25:44.00,0:25:46.00,Default,,0000,0000,0000,,you've got the whole thing down. Dialogue: 0,0:25:46.00,0:25:50.00,Default,,0000,0000,0000,,The STL map is like our map except that instead of going string to some value, it's Dialogue: 0,0:25:50.00,0:25:51.00,Default,,0000,0000,0000,,any key type you want Dialogue: 0,0:25:51.00,0:25:53.00,Default,,0000,0000,0000,,to any value type you want. Dialogue: 0,0:25:53.00,0:25:56.00,Default,,0000,0000,0000,,So you can map strings to ints, you can map ints to strings, Dialogue: 0,0:25:56.00,0:26:00.00,Default,,0000,0000,0000,,you can map stack of queue of int to vector of double. Dialogue: 0,0:26:00.00,0:26:04.00,Default,,0000,0000,0000,,I don't know why you would, but you have the ability to do so. Dialogue: 0,0:26:04.00,0:26:07.00,Default,,0000,0000,0000,,The problem is that the interface on map Dialogue: 0,0:26:07.00,0:26:11.00,Default,,0000,0000,0000,,was probably designed by someone who didn't like people. It's really hard Dialogue: 0,0:26:11.00,0:26:14.00,Default,,0000,0000,0000,,to use. Anyone who has used it will tell you that. Once you Dialogue: 0,0:26:14.00,0:26:17.00,Default,,0000,0000,0000,,get the hang of it, though, it's pretty intuitive. The result is you have a Dialogue: 0,0:26:17.00,0:26:22.00,Default,,0000,0000,0000,,very fast map container that is going to be the backbone of any of the programs that you write. Dialogue: 0,0:26:22.00,0:26:23.00,Default,,0000,0000,0000,,It's quite a useful class. Dialogue: 0,0:26:23.00,0:26:26.00,Default,,0000,0000,0000,,Again, I don't expect you to memorize every, single bit of syntax here, Dialogue: 0,0:26:26.00,0:26:27.00,Default,,0000,0000,0000,,everything I'm saying. Dialogue: 0,0:26:27.00,0:26:29.00,Default,,0000,0000,0000,,Just keep it in the back of the mind if this is what you want to look into. Dialogue: 0,0:26:29.00,0:26:33.00,Default,,0000,0000,0000,,The map you do need to know. Go take a look at that one if you want to Dialogue: 0,0:26:33.00,0:26:36.00,Default,,0000,0000,0000,,pursue C++. Now Dialogue: 0,0:26:36.00,0:26:37.00,Default,,0000,0000,0000,,iterators. Dialogue: 0,0:26:37.00,0:26:40.00,Default,,0000,0000,0000,,So the iterators you've seen in this class are very nice. They're well-behaved. Dialogue: 0,0:26:40.00,0:26:44.00,Default,,0000,0000,0000,,Has next, Dialogue: 0,0:26:44.00,0:26:45.00,Default,,0000,0000,0000,,next. Has next, Dialogue: 0,0:26:45.00,0:26:47.00,Default,,0000,0000,0000,,next. I'm done. [Inaudible] Dialogue: 0,0:26:47.00,0:26:50.00,Default,,0000,0000,0000,,iterators are designed to look like pointers. Dialogue: 0,0:26:50.00,0:26:53.00,Default,,0000,0000,0000,,You might wonder why anyone would voluntarily make something look like a Dialogue: 0,0:26:53.00,0:26:54.00,Default,,0000,0000,0000,,pointer. There's a very good reason. Dialogue: 0,0:26:54.00,0:26:58.00,Default,,0000,0000,0000,,This means they're about as smart as a pointer, which means they know Dialogue: 0,0:26:58.00,0:26:59.00,Default,,0000,0000,0000,,nothing. Dialogue: 0,0:26:59.00,0:27:02.00,Default,,0000,0000,0000,,So if you want to iterate over a range, you have to have two different iterators. You have Dialogue: 0,0:27:02.00,0:27:03.00,Default,,0000,0000,0000,,to say start here, Dialogue: 0,0:27:03.00,0:27:04.00,Default,,0000,0000,0000,,stop there, Dialogue: 0,0:27:04.00,0:27:07.00,Default,,0000,0000,0000,,keep walking forward until you get there. Dialogue: 0,0:27:07.00,0:27:08.00,Default,,0000,0000,0000,,Admittedly, Dialogue: 0,0:27:08.00,0:27:10.00,Default,,0000,0000,0000,,it's more work, Dialogue: 0,0:27:10.00,0:27:12.00,Default,,0000,0000,0000,,but it's very useful because it means that Dialogue: 0,0:27:12.00,0:27:15.00,Default,,0000,0000,0000,,if you want to iterate over a 20-element slice out of a 400 Dialogue: 0,0:27:15.00,0:27:17.00,Default,,0000,0000,0000,,million element container, Dialogue: 0,0:27:17.00,0:27:19.00,Default,,0000,0000,0000,,you can do that. Try doing that with our libraries. You have to go iterate all the Dialogue: 0,0:27:19.00,0:27:21.00,Default,,0000,0000,0000,,way up the start, Dialogue: 0,0:27:21.00,0:27:23.00,Default,,0000,0000,0000,,then keep iterating more. Dialogue: 0,0:27:23.00,0:27:26.00,Default,,0000,0000,0000,,The other thing you need to know about the iterators is that they're read/write. Dialogue: 0,0:27:26.00,0:27:30.00,Default,,0000,0000,0000,,So you can actually crawl over a container and update the values with an iterator, Dialogue: 0,0:27:30.00,0:27:32.00,Default,,0000,0000,0000,,something that you cannot do with our libraries. Dialogue: 0,0:27:32.00,0:27:35.00,Default,,0000,0000,0000,,It's a bit more work. The syntax basically looks like pointer reading and Dialogue: 0,0:27:35.00,0:27:35.00,Default,,0000,0000,0000,,writing, Dialogue: 0,0:27:35.00,0:27:40.00,Default,,0000,0000,0000,,but the result is that they're much more powerful, and they're a lot more flexible. Dialogue: 0,0:27:40.00,0:27:43.00,Default,,0000,0000,0000,,Here's a quick example. Dialogue: 0,0:27:43.00,0:27:46.00,Default,,0000,0000,0000,,I just wrote some code here that uses a vector iterator. The thing to take a look at is this Dialogue: 0,0:27:46.00,0:27:49.00,Default,,0000,0000,0000,,right here. Dialogue: 0,0:27:49.00,0:27:53.00,Default,,0000,0000,0000,,So basically, there's a couple parts to point out. I want to show you this so that if you Dialogue: 0,0:27:53.00,0:27:54.00,Default,,0000,0000,0000,,see this later on, Dialogue: 0,0:27:54.00,0:27:57.00,Default,,0000,0000,0000,,you'll get it. Can everybody see this? Dialogue: 0,0:27:57.00,0:27:59.00,Default,,0000,0000,0000,,The first thing is this begin function. Dialogue: 0,0:27:59.00,0:28:03.00,Default,,0000,0000,0000,,We call it iterator, they call it begin. It just says, give me a start iterator. Dialogue: 0,0:28:03.00,0:28:07.00,Default,,0000,0000,0000,,Since we need two iterators to define a range, we keep going until we hit this iterator called Dialogue: 0,0:28:07.00,0:28:09.00,Default,,0000,0000,0000,,N, which means stop. To Dialogue: 0,0:28:09.00,0:28:13.00,Default,,0000,0000,0000,,move the iterator forward, has next and next would be too nice, so it's ++, Dialogue: 0,0:28:13.00,0:28:15.00,Default,,0000,0000,0000,,and then to read from an iterator or write to it, you just de-reference Dialogue: 0,0:28:15.00,0:28:17.00,Default,,0000,0000,0000,,it. Dialogue: 0,0:28:17.00,0:28:20.00,Default,,0000,0000,0000,,So you do star iterator, as if it's a pointer, which in many cases, it Dialogue: 0,0:28:20.00,0:28:22.00,Default,,0000,0000,0000,,actually is. Dialogue: 0,0:28:22.00,0:28:24.00,Default,,0000,0000,0000,,That's the gist of what this looks like. There's a few more nuances Dialogue: 0,0:28:24.00,0:28:25.00,Default,,0000,0000,0000,,and subtleties, Dialogue: 0,0:28:25.00,0:28:28.00,Default,,0000,0000,0000,,but if you keep in mind that if you're looking at STL stuff, just treat this Dialogue: 0,0:28:28.00,0:28:34.00,Default,,0000,0000,0000,,like pointers, it will make a lot of sense. The Dialogue: 0,0:28:34.00,0:28:37.00,Default,,0000,0000,0000,,last thing I want to talk about are algorithms. These things are Dialogue: 0,0:28:37.00,0:28:40.00,Default,,0000,0000,0000,,amazing. The idea is that everything's got iterators, Dialogue: 0,0:28:40.00,0:28:42.00,Default,,0000,0000,0000,,so if you write functions that work on iterators, they will work on any Dialogue: 0,0:28:42.00,0:28:43.00,Default,,0000,0000,0000,,container type. Dialogue: 0,0:28:43.00,0:28:47.00,Default,,0000,0000,0000,,So if you want a binary search or a vector, you call binary search. Dialogue: 0,0:28:47.00,0:28:51.00,Default,,0000,0000,0000,,It's a prewritten function. You want to sort something? Great. Go call sort. Dialogue: 0,0:28:51.00,0:28:55.00,Default,,0000,0000,0000,,You guys have seen permutations before, right? You have to go do recursion pulsing in the Dialogue: 0,0:28:55.00,0:28:58.00,Default,,0000,0000,0000,,front, permute the rest, stick it back on, that sort of stuff? Dialogue: 0,0:28:58.00,0:29:00.00,Default,,0000,0000,0000,,STL, you can do it in a while loop. Dialogue: 0,0:29:00.00,0:29:02.00,Default,,0000,0000,0000,,You can while you next permutation something, Dialogue: 0,0:29:02.00,0:29:05.00,Default,,0000,0000,0000,,come up with every, single permutation, and you don't have to write a single recursive Dialogue: 0,0:29:05.00,0:29:07.00,Default,,0000,0000,0000,,function ever. Dialogue: 0,0:29:07.00,0:29:10.00,Default,,0000,0000,0000,,These sorts of things, I think there's 75 different algorithms, anything Dialogue: 0,0:29:10.00,0:29:12.00,Default,,0000,0000,0000,,from permuting to searching to sorting, Dialogue: 0,0:29:12.00,0:29:15.00,Default,,0000,0000,0000,,to transforming to rearranging to sorting to splitting. Dialogue: 0,0:29:15.00,0:29:18.00,Default,,0000,0000,0000,,You name it, there's probably an algorithm that does it. If Dialogue: 0,0:29:18.00,0:29:19.00,Default,,0000,0000,0000,,you play around with the STL, Dialogue: 0,0:29:19.00,0:29:26.00,Default,,0000,0000,0000,,you get to see all this stuff. It's a lot of fun. Dialogue: 0,0:29:26.00,0:29:29.00,Default,,0000,0000,0000,,I've just been showing you some of the libraries. That's basically all the library changes you need to Dialogue: 0,0:29:29.00,0:29:29.00,Default,,0000,0000,0000,,know. Dialogue: 0,0:29:29.00,0:29:32.00,Default,,0000,0000,0000,,Basically, everything you want to do is still there. Dialogue: 0,0:29:32.00,0:29:35.00,Default,,0000,0000,0000,,The syntax is a little different. Some of the libraries you'll have to write yourself, but it's Dialogue: 0,0:29:35.00,0:29:39.00,Default,,0000,0000,0000,,all there. It's not like you have to relearn everything from scratch. Dialogue: 0,0:29:39.00,0:29:42.00,Default,,0000,0000,0000,,But the libraries are only as good as the language is, Dialogue: 0,0:29:42.00,0:29:45.00,Default,,0000,0000,0000,,and there are a couple of language features of C++ that we didn't really talk about Dialogue: 0,0:29:45.00,0:29:48.00,Default,,0000,0000,0000,,in this class. I want to go over some of them because you will see them a lot in Dialogue: 0,0:29:48.00,0:29:50.00,Default,,0000,0000,0000,,professional code. Dialogue: 0,0:29:50.00,0:29:53.00,Default,,0000,0000,0000,,After all, you cannot use a library any more than you understand how the Dialogue: 0,0:29:53.00,0:29:55.00,Default,,0000,0000,0000,,language works. So getting a rough understanding of what this will do Dialogue: 0,0:29:55.00,0:29:59.00,Default,,0000,0000,0000,,will make your life easier in the long Dialogue: 0,0:29:59.00,0:30:01.00,Default,,0000,0000,0000,,run. The first thing I want to talk about is Dialogue: 0,0:30:01.00,0:30:06.00,Default,,0000,0000,0000,,const. You've seen const before in the context of const and my context equals five. Dialogue: 0,0:30:06.00,0:30:10.00,Default,,0000,0000,0000,,Just make a global constant. Saying that const makes global constants is Dialogue: 0,0:30:10.00,0:30:13.00,Default,,0000,0000,0000,,like saying a computer is something that adds numbers. Dialogue: 0,0:30:13.00,0:30:13.00,Default,,0000,0000,0000,,Yes, Dialogue: 0,0:30:13.00,0:30:17.00,Default,,0000,0000,0000,,but they can also run Windows, for example. Dialogue: 0,0:30:17.00,0:30:21.00,Default,,0000,0000,0000,,Const shows up just about everywhere. It's the little keyword that could. Dialogue: 0,0:30:21.00,0:30:24.00,Default,,0000,0000,0000,,You'd be amazed just how useful this little keyword can be. Dialogue: 0,0:30:24.00,0:30:26.00,Default,,0000,0000,0000,,The biggest thing that it does Dialogue: 0,0:30:26.00,0:30:29.00,Default,,0000,0000,0000,,is helps protect you against your own mistakes. Dialogue: 0,0:30:29.00,0:30:32.00,Default,,0000,0000,0000,,If you're writing a program and you know something shouldn't change, tag Dialogue: 0,0:30:32.00,0:30:33.00,Default,,0000,0000,0000,,it const Dialogue: 0,0:30:33.00,0:30:36.00,Default,,0000,0000,0000,,because that way, later down the lie, if you do accidentally change it, it says, Dialogue: 0,0:30:36.00,0:30:39.00,Default,,0000,0000,0000,,that's a mistake. Compiler error. You screwed up. Dialogue: 0,0:30:39.00,0:30:42.00,Default,,0000,0000,0000,,It protects you. That should've been a double equal, not Dialogue: 0,0:30:42.00,0:30:44.00,Default,,0000,0000,0000,,a single equal, Dialogue: 0,0:30:44.00,0:30:46.00,Default,,0000,0000,0000,,those sorts of things. Dialogue: 0,0:30:46.00,0:30:49.00,Default,,0000,0000,0000,,You've all probably seen that the C++ compiler doesn't treat anything as sacred. Like, oh, you don't Dialogue: 0,0:30:49.00,0:30:51.00,Default,,0000,0000,0000,,want to return Dialogue: 0,0:30:51.00,0:30:56.00,Default,,0000,0000,0000,,something? Or something like, oh, wow, you did single equal instead of double equal. Dialogue: 0,0:30:56.00,0:30:57.00,Default,,0000,0000,0000,,You're the boss. Dialogue: 0,0:30:57.00,0:31:00.00,Default,,0000,0000,0000,,The second you try to break const, it pulls out its big ruler of judgment and Dialogue: 0,0:31:00.00,0:31:04.00,Default,,0000,0000,0000,,whacks you on the wrist with it, like shame on your for breaking this constants. It Dialogue: 0,0:31:04.00,0:31:06.00,Default,,0000,0000,0000,,is the compiler trying to help you out. Dialogue: 0,0:31:06.00,0:31:08.00,Default,,0000,0000,0000,,Please know about this keyword. I'll give you Dialogue: 0,0:31:08.00,0:31:11.00,Default,,0000,0000,0000,,an example. See Dialogue: 0,0:31:11.00,0:31:15.00,Default,,0000,0000,0000,,this function prototype? Void do something takes a vector by reference. Dialogue: 0,0:31:15.00,0:31:18.00,Default,,0000,0000,0000,,So I've passed my vector into this function, and the question is, what's it going to Dialogue: 0,0:31:18.00,0:31:20.00,Default,,0000,0000,0000,,hold when it comes back? Dialogue: 0,0:31:20.00,0:31:22.00,Default,,0000,0000,0000,,Well, it could be the same. It Dialogue: 0,0:31:22.00,0:31:25.00,Default,,0000,0000,0000,,could be completely empty. There could be 137 copies of the Dialogue: 0,0:31:25.00,0:31:26.00,Default,,0000,0000,0000,,number 137. Dialogue: 0,0:31:26.00,0:31:28.00,Default,,0000,0000,0000,,You don't know. Dialogue: 0,0:31:28.00,0:31:31.00,Default,,0000,0000,0000,,In this class, we've shown you, pass by reference can be either for Dialogue: 0,0:31:31.00,0:31:33.00,Default,,0000,0000,0000,,efficiency reasons because it's not fast enough, Dialogue: 0,0:31:33.00,0:31:35.00,Default,,0000,0000,0000,,or it can be Dialogue: 0,0:31:35.00,0:31:37.00,Default,,0000,0000,0000,,because you want to actually change the thing. Dialogue: 0,0:31:37.00,0:31:40.00,Default,,0000,0000,0000,,It's difficult to see what this function does because you have no idea Dialogue: 0,0:31:40.00,0:31:43.00,Default,,0000,0000,0000,,which of those two it is. Dialogue: 0,0:31:43.00,0:31:46.00,Default,,0000,0000,0000,,The idea, though, and this is something that you will see in professional code everywhere, Dialogue: 0,0:31:46.00,0:31:48.00,Default,,0000,0000,0000,,is doing something like this. Dialogue: 0,0:31:48.00,0:31:51.00,Default,,0000,0000,0000,,If I say, void do something const Dialogue: 0,0:31:51.00,0:31:53.00,Default,,0000,0000,0000,,vector and my vector, Dialogue: 0,0:31:53.00,0:31:56.00,Default,,0000,0000,0000,,that says that this vector can't be modified within the function. Dialogue: 0,0:31:56.00,0:32:00.00,Default,,0000,0000,0000,,It's like handing this thing off saying, I'm giving you this value Dialogue: 0,0:32:00.00,0:32:01.00,Default,,0000,0000,0000,,for efficiency reasons. Dialogue: 0,0:32:01.00,0:32:04.00,Default,,0000,0000,0000,,Donft try to modify it. In fact, you can't modify it. Dialogue: 0,0:32:04.00,0:32:07.00,Default,,0000,0000,0000,,It makes your code self-documenting. Someone looking at your functions can go, Dialogue: 0,0:32:07.00,0:32:09.00,Default,,0000,0000,0000,,that's const. I can't possibly change anything there, Dialogue: 0,0:32:09.00,0:32:13.00,Default,,0000,0000,0000,,and they'll be totally fine handing off the string containing their graduate thesis Dialogue: 0,0:32:13.00,0:32:14.00,Default,,0000,0000,0000,,to it, for example. Dialogue: 0,0:32:14.00,0:32:18.00,Default,,0000,0000,0000,,If you had your graduate thesis stored as a string, Dialogue: 0,0:32:18.00,0:32:19.00,Default,,0000,0000,0000,,which I don't Dialogue: 0,0:32:19.00,0:32:20.00,Default,,0000,0000,0000,,know why you would ever do this, Dialogue: 0,0:32:20.00,0:32:24.00,Default,,0000,0000,0000,,but if you see a function take the string and parameter, you'd probably be a little Dialogue: 0,0:32:24.00,0:32:27.00,Default,,0000,0000,0000,,bit worried. Like, is it going to replace my graduate thesis with, Dialogue: 0,0:32:27.00,0:32:30.00,Default,,0000,0000,0000,,hi, I don't have a graduate thesis or what? Dialogue: 0,0:32:30.00,0:32:34.00,Default,,0000,0000,0000,,The const is useful. Dialogue: 0,0:32:34.00,0:32:36.00,Default,,0000,0000,0000,,The question is, if it's such a useful keyword, Dialogue: 0,0:32:36.00,0:32:39.00,Default,,0000,0000,0000,,why didn't we show you this? Dialogue: 0,0:32:39.00,0:32:43.00,Default,,0000,0000,0000,,The biggest reason is you can't just use const every now and then. You can't say, I'm going Dialogue: 0,0:32:43.00,0:32:47.00,Default,,0000,0000,0000,,to mark this parameter const. I'm gong to say that one's const right there. It Dialogue: 0,0:32:47.00,0:32:48.00,Default,,0000,0000,0000,,doesn't work that way. Dialogue: 0,0:32:48.00,0:32:52.00,Default,,0000,0000,0000,,Let's say I do mark something const. That object has to know how to behave Dialogue: 0,0:32:52.00,0:32:53.00,Default,,0000,0000,0000,,when it can't modify itself. Dialogue: 0,0:32:53.00,0:32:56.00,Default,,0000,0000,0000,,So you have to make the entire class written const correct. Dialogue: 0,0:32:56.00,0:32:59.00,Default,,0000,0000,0000,,Then if it has any data members that are classes, that class has to be const correct. You get this Dialogue: 0,0:32:59.00,0:33:00.00,Default,,0000,0000,0000,, Dialogue: 0,0:33:00.00,0:33:01.00,Default,,0000,0000,0000,,exploding effect where Dialogue: 0,0:33:01.00,0:33:05.00,Default,,0000,0000,0000,,you stick a singe const in, and suddenly every, single piece of your code is marked Dialogue: 0,0:33:05.00,0:33:06.00,Default,,0000,0000,0000,,const. Dialogue: 0,0:33:06.00,0:33:09.00,Default,,0000,0000,0000,,That's a good thing because it makes your code self-documenting, Dialogue: 0,0:33:09.00,0:33:13.00,Default,,0000,0000,0000,,but the point is it's an unnecessary language complication. When Dialogue: 0,0:33:13.00,0:33:16.00,Default,,0000,0000,0000,,you're trying to write the PQ class, you should be worried, how do I build a Dialogue: 0,0:33:16.00,0:33:17.00,Default,,0000,0000,0000,,chunk list, not oh, Dialogue: 0,0:33:17.00,0:33:20.00,Default,,0000,0000,0000,,is this function const? So in the Dialogue: 0,0:33:20.00,0:33:23.00,Default,,0000,0000,0000,,professional world, you will see it. Here we thought, it makes things too Dialogue: 0,0:33:23.00,0:33:28.00,Default,,0000,0000,0000,,complicated. We'll give it a pass for right Dialogue: 0,0:33:28.00,0:33:30.00,Default,,0000,0000,0000,,now. Another big one. Object copying an assignment. Dialogue: 0,0:33:30.00,0:33:34.00,Default,,0000,0000,0000,,You've seen disallow copy. It says, don't copy this Dialogue: 0,0:33:34.00,0:33:38.00,Default,,0000,0000,0000,,object. It's not standard C++, but I've been told that Google actually Dialogue: 0,0:33:38.00,0:33:41.00,Default,,0000,0000,0000,,has a macro that does something just like this, so you're programming the same way Google Dialogue: 0,0:33:41.00,0:33:42.00,Default,,0000,0000,0000,,people do. Dialogue: 0,0:33:42.00,0:33:43.00,Default,,0000,0000,0000,,The difference is that Dialogue: 0,0:33:43.00,0:33:45.00,Default,,0000,0000,0000,,if you're trying to write a PQ Dialogue: 0,0:33:45.00,0:33:47.00,Default,,0000,0000,0000,,and it can't copy itself, Dialogue: 0,0:33:47.00,0:33:51.00,Default,,0000,0000,0000,,it's a little bit frustrating. Think about it. You make some PQ. You can make a vector Dialogue: 0,0:33:51.00,0:33:51.00,Default,,0000,0000,0000,,copy. Dialogue: 0,0:33:51.00,0:33:52.00,Default,,0000,0000,0000,,You can make a map copy. Dialogue: 0,0:33:52.00,0:33:56.00,Default,,0000,0000,0000,,If you can't make a PQ copy, you'll be wondering, why not? Dialogue: 0,0:33:56.00,0:33:59.00,Default,,0000,0000,0000,,So it turns out C++ lets you redefine the way copying Dialogue: 0,0:33:59.00,0:34:01.00,Default,,0000,0000,0000,,works. So these two functions here Dialogue: 0,0:34:01.00,0:34:04.00,Default,,0000,0000,0000,,called copy constructors and assignment operators. Dialogue: 0,0:34:04.00,0:34:07.00,Default,,0000,0000,0000,,While it's very useful to know how to do this, there's a major reason we didn't tell Dialogue: 0,0:34:07.00,0:34:08.00,Default,,0000,0000,0000,,you about it in this class. Dialogue: 0,0:34:08.00,0:34:12.00,Default,,0000,0000,0000,,It's because it's really hard. Dialogue: 0,0:34:12.00,0:34:16.00,Default,,0000,0000,0000,,I think I spent, in 106L, an entire week going over this. Dialogue: 0,0:34:16.00,0:34:18.00,Default,,0000,0000,0000,,We don't have a week to tell you how to do this. Dialogue: 0,0:34:18.00,0:34:21.00,Default,,0000,0000,0000,,Here's a list of some of the things you have to keep in mind when writing these Dialogue: 0,0:34:21.00,0:34:21.00,Default,,0000,0000,0000,,functions. Dialogue: 0,0:34:21.00,0:34:25.00,Default,,0000,0000,0000,,[Inaudible] to clean up your own memory, not memory you don't own. To clean Dialogue: 0,0:34:25.00,0:34:28.00,Default,,0000,0000,0000,,up the memory, to copy an object, to copy the object correctly, to handle Dialogue: 0,0:34:28.00,0:34:31.00,Default,,0000,0000,0000,,these [inaudible], to follow the same rules that C++ syntax dictates. Dialogue: 0,0:34:31.00,0:34:34.00,Default,,0000,0000,0000,,There's an awful lot of stuff going on there. Dialogue: 0,0:34:34.00,0:34:37.00,Default,,0000,0000,0000,,To expect you to get all this right when you're worrying about your PQ is just Dialogue: 0,0:34:37.00,0:34:37.00,Default,,0000,0000,0000,,too much. Dialogue: 0,0:34:37.00,0:34:40.00,Default,,0000,0000,0000,,It really is. Dialogue: 0,0:34:40.00,0:34:41.00,Default,,0000,0000,0000,,Imagine it's the day before it's due. Dialogue: 0,0:34:41.00,0:34:43.00,Default,,0000,0000,0000,,You've got the PQ working beautifully, and Dialogue: 0,0:34:43.00,0:34:45.00,Default,,0000,0000,0000,,it doesn't copy Dialogue: 0,0:34:45.00,0:34:49.00,Default,,0000,0000,0000,,right. What does that tell you? You've written your copy function wrong, but you totally Dialogue: 0,0:34:49.00,0:34:50.00,Default,,0000,0000,0000,,understand and made your point, Dialogue: 0,0:34:50.00,0:34:52.00,Default,,0000,0000,0000,,which is how to build a priority queue. Dialogue: 0,0:34:52.00,0:34:54.00,Default,,0000,0000,0000,,This is a chunk list. This is a heap. Dialogue: 0,0:34:54.00,0:34:55.00,Default,,0000,0000,0000,,This is an unsorted Dialogue: 0,0:34:55.00,0:34:58.00,Default,,0000,0000,0000,,vector. That's what's actually important, not building stuff like this. Dialogue: 0,0:34:58.00,0:35:00.00,Default,,0000,0000,0000,,When you're in the professional world, Dialogue: 0,0:35:00.00,0:35:03.00,Default,,0000,0000,0000,,you do need to do some extra work to make your objects copy Dialogue: 0,0:35:03.00,0:35:07.00,Default,,0000,0000,0000,,correctly. So you should look into these functions a little bit. Dialogue: 0,0:35:07.00,0:35:08.00,Default,,0000,0000,0000,,Again, to stress, Dialogue: 0,0:35:08.00,0:35:11.00,Default,,0000,0000,0000,,the stuff you've learned in here, the actual here's how you build these data Dialogue: 0,0:35:11.00,0:35:14.00,Default,,0000,0000,0000,,structures, is more important than these global syntactic nuances that you've got to be Dialogue: 0,0:35:14.00,0:35:18.00,Default,,0000,0000,0000,,aware of. Dialogue: 0,0:35:18.00,0:35:20.00,Default,,0000,0000,0000,,One more thing. This is pretty cool. Dialogue: 0,0:35:20.00,0:35:22.00,Default,,0000,0000,0000,,I have this Dialogue: 0,0:35:22.00,0:35:23.00,Default,,0000,0000,0000,,code snippet right here. Dialogue: 0,0:35:23.00,0:35:24.00,Default,,0000,0000,0000,,I make a string, Dialogue: 0,0:35:24.00,0:35:25.00,Default,,0000,0000,0000,,and I say, Dialogue: 0,0:35:25.00,0:35:30.00,Default,,0000,0000,0000,,my string is equal to this is, and then I tack onto it, a string. Dialogue: 0,0:35:30.00,0:35:32.00,Default,,0000,0000,0000,,I'm going to iterate over this entire string, Dialogue: 0,0:35:32.00,0:35:35.00,Default,,0000,0000,0000,,and every step, I'm going to print out the current character. So Dialogue: 0,0:35:35.00,0:35:37.00,Default,,0000,0000,0000,,this is just print out the string Dialogue: 0,0:35:37.00,0:35:39.00,Default,,0000,0000,0000,,one letter at a time. Ifm going to Dialogue: 0,0:35:39.00,0:35:42.00,Default,,0000,0000,0000,,highlight a few things. Dialogue: 0,0:35:42.00,0:35:45.00,Default,,0000,0000,0000,,Why is it legal to [inaudible] equals a string with something else? Dialogue: 0,0:35:45.00,0:35:48.00,Default,,0000,0000,0000,,Why string but not priority queue? Why are we allow to do this? Dialogue: 0,0:35:48.00,0:35:50.00,Default,,0000,0000,0000,,It's a string. It's an Dialogue: 0,0:35:50.00,0:35:54.00,Default,,0000,0000,0000,,object, and we just code plus equals on it. Dialogue: 0,0:35:54.00,0:35:56.00,Default,,0000,0000,0000,,Why does it let you do less than, less than? Dialogue: 0,0:35:56.00,0:35:59.00,Default,,0000,0000,0000,,What does that mean? Why do streams let you do that but nothing else? Why can Dialogue: 0,0:35:59.00,0:36:03.00,Default,,0000,0000,0000,,I read a string with brackets even though it's really an object? Dialogue: 0,0:36:03.00,0:36:07.00,Default,,0000,0000,0000,,At a high level, we all know what it means to add something to a string. It Dialogue: 0,0:36:07.00,0:36:11.00,Default,,0000,0000,0000,,means take something and stick it on. You know what this less than, less than. It means put into Dialogue: 0,0:36:11.00,0:36:14.00,Default,,0000,0000,0000,,a stream. Dialogue: 0,0:36:14.00,0:36:18.00,Default,,0000,0000,0000,,[Inaudible] C++, I want to define these operators for my classes. Dialogue: 0,0:36:18.00,0:36:21.00,Default,,0000,0000,0000,,It's a technique known as operator overloading. Dialogue: 0,0:36:21.00,0:36:25.00,Default,,0000,0000,0000,,Basically, all you do is write functions that are called operator and Dialogue: 0,0:36:25.00,0:36:28.00,Default,,0000,0000,0000,,whatever the name of your operator is. So operator equals, operator brackets, operator Dialogue: 0,0:36:28.00,0:36:29.00,Default,,0000,0000,0000,,less than, less than. Dialogue: 0,0:36:29.00,0:36:30.00,Default,,0000,0000,0000,,Operator plus, plus. Dialogue: 0,0:36:30.00,0:36:34.00,Default,,0000,0000,0000,,It's just a syntax convenience. You can write code that looks more Dialogue: 0,0:36:34.00,0:36:34.00,Default,,0000,0000,0000,,intuitive Dialogue: 0,0:36:34.00,0:36:37.00,Default,,0000,0000,0000,,that does something complex behind the scenes. For Dialogue: 0,0:36:37.00,0:36:41.00,Default,,0000,0000,0000,,example, if I write my vector bracket I, it's not like, oh, it's a bracket. It's much Dialogue: 0,0:36:41.00,0:36:43.00,Default,,0000,0000,0000,,faster. It really means, call the function called Dialogue: 0,0:36:43.00,0:36:45.00,Default,,0000,0000,0000,,operator brackets. Dialogue: 0,0:36:45.00,0:36:49.00,Default,,0000,0000,0000,,Again, it's a convenience and nothing else. If you treat it as anything more than a Dialogue: 0,0:36:49.00,0:36:51.00,Default,,0000,0000,0000,,convenience, you can kind of hurt yourself with it. Dialogue: 0,0:36:51.00,0:36:54.00,Default,,0000,0000,0000,,You can overload basically every operator in C++. You can Dialogue: 0,0:36:54.00,0:36:58.00,Default,,0000,0000,0000,,overload things like bit wise [inaudible] with assignment. You can overload the Dialogue: 0,0:36:58.00,0:37:01.00,Default,,0000,0000,0000,,exore operator. You can overload parenthesis, and, comma, Dialogue: 0,0:37:01.00,0:37:03.00,Default,,0000,0000,0000,,all these operators that most people never use. Dialogue: 0,0:37:03.00,0:37:06.00,Default,,0000,0000,0000,,The ones that you see most frequently, though, are these Dialogue: 0,0:37:06.00,0:37:09.00,Default,,0000,0000,0000,,ones. Overloading operator less than, less than for stream insertion. Dialogue: 0,0:37:09.00,0:37:12.00,Default,,0000,0000,0000,,You can actually make it so that you can make a vector class than Dialogue: 0,0:37:12.00,0:37:15.00,Default,,0000,0000,0000,,can print itself out to the screen. It's kind Dialogue: 0,0:37:15.00,0:37:17.00,Default,,0000,0000,0000,,of useful. The assignment operator, operator equals, Dialogue: 0,0:37:17.00,0:37:20.00,Default,,0000,0000,0000,,the less than operator for comparing things and the parentheses operator. Dialogue: 0,0:37:20.00,0:37:23.00,Default,,0000,0000,0000,,You can actually overload parentheses. It's pretty cool stuff. It's Dialogue: 0,0:37:23.00,0:37:27.00,Default,,0000,0000,0000,,actually for something called functors, which is really awesome. If you do play around with Dialogue: 0,0:37:27.00,0:37:30.00,Default,,0000,0000,0000,,C++, this is definitely something to keep in mind because it will make your Dialogue: 0,0:37:30.00,0:37:33.00,Default,,0000,0000,0000,,life a lot more enjoyable. Dialogue: 0,0:37:33.00,0:37:36.00,Default,,0000,0000,0000,,I think more than any other language features, C++, except possibly Dialogue: 0,0:37:36.00,0:37:40.00,Default,,0000,0000,0000,,multiple inherence, this is the most widely-criticized Dialogue: 0,0:37:40.00,0:37:41.00,Default,,0000,0000,0000,,feature of the language. Dialogue: 0,0:37:41.00,0:37:44.00,Default,,0000,0000,0000,,The reason is that you can make things that make no sense legal. Dialogue: 0,0:37:44.00,0:37:47.00,Default,,0000,0000,0000,,Like, defining the modular operator for two Dialogue: 0,0:37:47.00,0:37:50.00,Default,,0000,0000,0000,,PQ. My PQ, my other PQ. Anybody think Dialogue: 0,0:37:50.00,0:37:54.00,Default,,0000,0000,0000,,of a sensible interpretation of what it means to mod one PQ by Dialogue: 0,0:37:54.00,0:37:57.00,Default,,0000,0000,0000,,another? If you do, please send me an email or Dialogue: 0,0:37:57.00,0:37:59.00,Default,,0000,0000,0000,,shout it out right now. I can't think of one. Dialogue: 0,0:37:59.00,0:38:01.00,Default,,0000,0000,0000,,But you can make it legal. Dialogue: 0,0:38:01.00,0:38:04.00,Default,,0000,0000,0000,,I don't know why you would, but you can. Dialogue: 0,0:38:04.00,0:38:05.00,Default,,0000,0000,0000,,The point of this is, if you think Dialogue: 0,0:38:05.00,0:38:07.00,Default,,0000,0000,0000,,about it, call it the philosophy. Let Dialogue: 0,0:38:07.00,0:38:11.00,Default,,0000,0000,0000,,the programmer make the choice, even if it lets them choose wrong. Dialogue: 0,0:38:11.00,0:38:14.00,Default,,0000,0000,0000,,You can do this. You probably shouldn't do it, but Dialogue: 0,0:38:14.00,0:38:16.00,Default,,0000,0000,0000,,by giving you the opportunity to do so, Dialogue: 0,0:38:16.00,0:38:19.00,Default,,0000,0000,0000,,it means that when you really do need to write a class that has a module Dialogue: 0,0:38:19.00,0:38:21.00,Default,,0000,0000,0000,,that's defined, you can do it. Dialogue: 0,0:38:21.00,0:38:22.00,Default,,0000,0000,0000,,It's flexibility. It Dialogue: 0,0:38:22.00,0:38:23.00,Default,,0000,0000,0000,,means that you have to Dialogue: 0,0:38:23.00,0:38:30.00,Default,,0000,0000,0000,,make sure that what you're doing makes sense, but it's flexibility. You've Dialogue: 0,0:38:30.00,0:38:32.00,Default,,0000,0000,0000,,all just finished Pathfinder, right? Dialogue: 0,0:38:32.00,0:38:37.00,Default,,0000,0000,0000,,Did anybody templatize the [inaudible] PQ, by any chance? Anyone? You guys Dialogue: 0,0:38:37.00,0:38:39.00,Default,,0000,0000,0000,,are smart. Dialogue: 0,0:38:39.00,0:38:44.00,Default,,0000,0000,0000,,Here's the thing. Let's say I wrote something that says, A equals B. Dialogue: 0,0:38:44.00,0:38:47.00,Default,,0000,0000,0000,,What does this mean? It says assign B Dialogue: 0,0:38:47.00,0:38:49.00,Default,,0000,0000,0000,,A. What if I write this in a template function? Dialogue: 0,0:38:49.00,0:38:53.00,Default,,0000,0000,0000,,I have a template of some unknown type. I'll just say A equals B. Dialogue: 0,0:38:53.00,0:38:54.00,Default,,0000,0000,0000,,What's it mean? Dialogue: 0,0:38:54.00,0:38:58.00,Default,,0000,0000,0000,,Well, if it's an int, it means take the int and copy it. If it's a floating point Dialogue: 0,0:38:58.00,0:39:01.00,Default,,0000,0000,0000,,number, it says take the floating point number and copy it. If Dialogue: 0,0:39:01.00,0:39:04.00,Default,,0000,0000,0000,,it's a string, it says make a string deep copy. Dialogue: 0,0:39:04.00,0:39:08.00,Default,,0000,0000,0000,,The point is that every, single time you use this same syntax, A equals B, Dialogue: 0,0:39:08.00,0:39:11.00,Default,,0000,0000,0000,,but the result is different, and it's always the correct result. Dialogue: 0,0:39:11.00,0:39:15.00,Default,,0000,0000,0000,,This is what you can get with operator [inaudible], the ability to take code Dialogue: 0,0:39:15.00,0:39:19.00,Default,,0000,0000,0000,,and make it look right for every, single class so that in templates, you can just Dialogue: 0,0:39:19.00,0:39:23.00,Default,,0000,0000,0000,,call the function, and you're guaranteed it will work. Dialogue: 0,0:39:23.00,0:39:26.00,Default,,0000,0000,0000,,That's a quick tour of some of the language features. I know this Dialogue: 0,0:39:26.00,0:39:30.00,Default,,0000,0000,0000,,might seem like an awful lot. I've been going very quickly through it, Dialogue: 0,0:39:30.00,0:39:33.00,Default,,0000,0000,0000,,but want to conclude by saying so what? Dialogue: 0,0:39:33.00,0:39:37.00,Default,,0000,0000,0000,,I just harangued you with a lot of language features, a lot of syntax, a lot of Dialogue: 0,0:39:37.00,0:39:37.00,Default,,0000,0000,0000,,libraries. Dialogue: 0,0:39:37.00,0:39:39.00,Default,,0000,0000,0000,,What's the point? Dialogue: 0,0:39:39.00,0:39:41.00,Default,,0000,0000,0000,,The point to take out of this is that Dialogue: 0,0:39:41.00,0:39:43.00,Default,,0000,0000,0000,,C++ is big, Dialogue: 0,0:39:43.00,0:39:46.00,Default,,0000,0000,0000,,but it's also a very powerful language, and it's a very expressive language. I Dialogue: 0,0:39:46.00,0:39:48.00,Default,,0000,0000,0000,,think it's a very beautiful language. Dialogue: 0,0:39:48.00,0:39:51.00,Default,,0000,0000,0000,,The features that you've learned in this class will go anywhere you want them to. Dialogue: 0,0:39:51.00,0:39:54.00,Default,,0000,0000,0000,,If you want to take your coding skills Dialogue: 0,0:39:54.00,0:39:55.00,Default,,0000,0000,0000,,and apply Dialogue: 0,0:39:55.00,0:39:57.00,Default,,0000,0000,0000,,them to C++, you can, Dialogue: 0,0:39:57.00,0:39:58.00,Default,,0000,0000,0000,,and you have this flexibility. Dialogue: 0,0:39:58.00,0:40:00.00,Default,,0000,0000,0000,,You really have this gift. Dialogue: 0,0:40:00.00,0:40:03.00,Default,,0000,0000,0000,,What you've learned in here is something most people never learn. It's how to make Dialogue: 0,0:40:03.00,0:40:05.00,Default,,0000,0000,0000,,a computer solve a problem for you. Dialogue: 0,0:40:05.00,0:40:07.00,Default,,0000,0000,0000,,That's a skill that's going to follow you for the rest of your life, no matter where Dialogue: 0,0:40:07.00,0:40:09.00,Default,,0000,0000,0000,,you take it. Dialogue: 0,0:40:09.00,0:40:12.00,Default,,0000,0000,0000,,If you're interested in C++, I have a huge number of references here, if you Dialogue: 0,0:40:12.00,0:40:13.00,Default,,0000,0000,0000,,want to go see them. Dialogue: 0,0:40:13.00,0:40:16.00,Default,,0000,0000,0000,,The point is that if you want to solve a problem with a computer, you need three things. Dialogue: 0,0:40:16.00,0:40:19.00,Default,,0000,0000,0000,,First, Dialogue: 0,0:40:19.00,0:40:20.00,Default,,0000,0000,0000,,programming skills. Dialogue: 0,0:40:20.00,0:40:21.00,Default,,0000,0000,0000,,You all have that. Dialogue: 0,0:40:21.00,0:40:23.00,Default,,0000,0000,0000,,You need a good idea. Dialogue: 0,0:40:23.00,0:40:26.00,Default,,0000,0000,0000,,I don't think I have any good ideas for programming. If I did, I'd probably do them myself, Dialogue: 0,0:40:26.00,0:40:29.00,Default,,0000,0000,0000,,but if you have a good idea, and you want to make $1 billion with it, the Dialogue: 0,0:40:29.00,0:40:32.00,Default,,0000,0000,0000,,last thing you need is a programming language. Dialogue: 0,0:40:32.00,0:40:35.00,Default,,0000,0000,0000,,Hopefully this quick tour of C++ has showed you. This Dialogue: 0,0:40:35.00,0:40:38.00,Default,,0000,0000,0000,,is what this language is. It's a tool for solving real problems Dialogue: 0,0:40:38.00,0:40:40.00,Default,,0000,0000,0000,,that trusts you Dialogue: 0,0:40:40.00,0:40:41.00,Default,,0000,0000,0000,,and that means that overall, you'll Dialogue: 0,0:40:41.00,0:40:43.00,Default,,0000,0000,0000,,have fun doing it. Dialogue: 0,0:40:43.00,0:40:45.00,Default,,0000,0000,0000,,So if you want to go and run with this, if you want to say, I'm a good programmer. Dialogue: 0,0:40:45.00,0:40:46.00,Default,,0000,0000,0000,,I can do this and Dialogue: 0,0:40:46.00,0:40:49.00,Default,,0000,0000,0000,,learn C++. I think you will love it. I think you will enjoy it. I think it will Dialogue: 0,0:40:49.00,0:40:53.00,Default,,0000,0000,0000,,be some of the most fun you will have sitting in front of a computer. Dialogue: 0,0:40:53.00,0:40:56.00,Default,,0000,0000,0000,,So have fun with this stuff. That's the whole point. If you're in this class, I hope Dialogue: 0,0:40:56.00,0:41:00.00,Default,,0000,0000,0000,,you enjoy it. I hope you said, yeah, I can make a computer solve something. I can do graph Dialogue: 0,0:41:00.00,0:41:01.00,Default,,0000,0000,0000,,algorithms. I can do graph [inaudible]. Dialogue: 0,0:41:01.00,0:41:04.00,Default,,0000,0000,0000,,I can make data structures. I can make a computer program that plays Boggle Dialogue: 0,0:41:04.00,0:41:08.00,Default,,0000,0000,0000,,better than I ever could or anyone I know ever can. Dialogue: 0,0:41:08.00,0:41:10.00,Default,,0000,0000,0000,,Have fun. That's the whole point of this. Dialogue: 0,0:41:10.00,0:41:14.00,Default,,0000,0000,0000,,If you want to do it in C++, come talk to me. I will give you some references. Dialogue: 0,0:41:14.00,0:41:17.00,Default,,0000,0000,0000,,Enjoy. Good luck on the final, and I will probably see you around on Friday for the final. Dialogue: 0,0:41:17.00,0:41:18.00,Default,,0000,0000,0000,,Enjoy.