Now, as gunshots echo across the windswept snow-covered regions of the wild northwest, Quaker Pop Week and Quaker Pop Rice, the breakfast cereal shot from guns, present the challenge of the Yukon. It's Yukon King, swiftest and strongest lead dog of the Northwest, blazing the trail for Sergeant Preston of the Northwest Monument Police in his relentless pursuit of lawbreakers. Gold. Gold discovered in the Yukon. A stampede to the Klondike in the wild race for riches. Back to the days of the Gold Rush. With Quaker Pop Week and Quaker Pop Rice bring you the adventures of Sergeant Preston and his Wonder Dog Yukon King as they meet the challenge of the Yukon. Going, going, gone. That's the way Quaker Pop Weeder Rice disappears at breakfast time. These ready to serve cereals hit the spot from first to last delicious spoonful. Yes, Weeder Rice shot from guns is exploded up to eight times normal size to make it crisp and tender. Tomorrow morning, fill a bowl with Quaker Pop Weeder Rice topped with fruit, like, say, uh, sliced bananas, add milk and sugar, and say, do you know what? There's no beating this eating. That's what. Ben Taylor was a kindly old prospector who lived in his cabin near his claim about two miles outside the little settlement of Dundee. Old Ben's grandson Bobby, ten years old, lived with him. Bobby was an orphan and thought his grandfather was the finest and bravest man in all the Yukon territory. Old Ben had built himself up in Bobby's estimation by the many heroic tales he told the boy. Though the people in Dundee laughed at Old Ben's habit of stretching the truth, they regarded him as a harmless and liable old sourdough. One cold, bleak day as he and Bobby journeyed the two miles to the settlement by dog sled. Old Ben, as usual, was telling the boy of his various past adventures. Yes, like I was saying, Bobby, I've done my bit to bring law and order to this year. Yukon territory? Yes, sir. Well, I recollect the time that you mean you belong to the Maudi's grandpa? Well, I didn't say that, son, but I reckon they would have took me on if I had told them I was willing.  March! Oh, where was I? Oh, yes, like I was saying, I recollect the time I was over in Selkirk when there was a ruckus in the Trayton Post there.  Gee, what did you do? Well, I stopped my sled, pulled out my stick, sure it went barging right on in. I can tell you, Bobby, that robber liked to drop in his boots when he saw me standing there looking mean as if busy. Oh, gosh, then what? Well, what you expect? He dropped his gun, put up his hands, and gave up right then and there. Even a Maudi couldn't have done that good. No, sir. Mother Weber at the Trayton Post and Dundee told me once about a Maudi named Sergeant Preston and his dog King. I bet they would have caught that robber, too. Sergeant Preston of the Maudis, huh? Funny thing, but I was just going to tell you about the time I helped him track down a couple crooks. Sergeant Preston and King? King. Oh, his dog. The one Mother Weber told me about. Oh, you meant Preston's dog King. Well, why didn't you say so? Sure, sure, Bobby. Preston and King are good friends of mine. God. Why didn't you tell me that before, Grandpa? Why? Just never come from a mile, I reckon. Mother Weber said King won't mind anyone but Sergeant Preston.  Why many is the time when Sergeant Preston and me and King was tracking down some chup crooks? If Sergeant would say to me, he'd say, Ban me, say? Even King respects the way you can quit drawing a crook the way you... Hi, sir, Mother. What's it? Hey. Hi, sir. That dog sledding two men up ahead is coming from the side. Like they were fixing to cut us off. Well, love, Grandpa. Both those men have things over their faces, so only their eyes show. Jumping, Judy. Maybe they're fixing to hold us up. And me with all my gold in the sledding. Hold it there, everyone. Hold it there. Hold it. Hold it. Hold it. Hold it. Hold it. Now, look at here, mister. It's quite cold in here.  You heard what he told you? Hey, that dog... We've been watching you. We know you do pretty well at that claim of yours. And we figure you might be bringing in the take from your claim right now. Oh, no. No, I... Take him away, Grandpa. If they knew you used to help Sergeant Preston... Get up, kid. Have you heard that, dude? Yo, Gordia told his kid he used to help Sergeant Preston. Must have swept out his cabin with those stubby whiskers he is. Yeah. Look at him shake, will you? And I'm just cool, that's all.  Or do we have to shake it up? No, wait, wait, wait. Now, it's under the covers of the sled. Now, get it. It isn't much, but it's all I have. See this bag. You made that. So bad, right? If my grandpa gets mad, you'll both be sorry, I bet. Won't they, Grandpa? Yeah, quiet, Bobby. Quiet. Well, Gordia, are you gonna get mad at us? What do you want us to... Oh, no, no, I... I'm not mad at anybody right now. You see... Ah, come on. Look, before they all catch us, ship us right out of his pocket. Yeah. Let's go. Right. Right. There you go. Yeah, there they go with three months of my taking the claim. Well, don't let them get away, Grandpa. Use your gun. Huh? Oh, yeah. Sure. Sure. Now I am getting mad. I'll... I'll see you. My hand is cold. But, see, Grandpa, that's all you told me about how you... Well, never mind, Bobby. Never mind all that now. We gotta go on to Dundee. Mush, you aren't gonna... Mush! It was early the following night when Sergeant Preston and King arrived in little settlement of Dundee. He was ever a trading post. Come on, King. Come on, Bob. Oh, so is the Sergeant Preston. Hello, Hans. Oh, thanks, Bling. Oh, fine, fine, Sergeant. And there is King too, yeah. Say hello to Mr. Weber, King. Ah, so, King always knows what you say, huh? He understands pretty well. You come, I suppose, to see your good friend, old Ben Taylor. Ben Taylor?  I know you don't know him. He's an old prospector who lives alone with his grandson, Bobby.  He don't feel so good about his grandpa right now. But yesterday, old Ben was coming to Dundee with a boy from their cabin two miles west of here. A couple of men held him off and took Ben's little back of gold. I see. It's too bad it's snow during the night. King and I might have been able to track him. Oh, Ben feels worse about the boy. You mean they harmed the boy? No, no, no, no, nothing like that. It's Ben himself who did the damage. She knows he's always telling the boy stories about himself, making them up, you know. I see. Go on. Well, yesterday we find out that he even told Bobby that he was a friend of yours and King and that he helped you track down cooks. That's something. About the boy, huh? Well, he was here with old Ben and everyone laughing on his grandfather. And Bobby lost faith in his grandfather, is that it? Yes, yes, of course. Bobby told us, but then it said. Then everyone laughed and said that Ben didn't know you at all.  He went away with tears in his eyes. He thought his grandfather was a hero, you see. Of course it's wrong for old Ben to tell things that aren't true, but it's worse to have that little boy lose faith in one he loves. Perhaps Bobby will feel differently and the folks around here won't laugh at old Ben much longer. You don't mean you do know old Ben such. You'll find out what I mean, Hans, in due time. Come on, King, we have something to do. Later that night, as the wind moaned about their little cabin, old Ben and his grandson Bobby sat near the warmth-giving pot-bellied stove in silence. Several times Ben glanced at the boy, but Bobby stared at the floor. Then old Ben cleared his throat loudly and spoke. Say, Bobby, did I ever tell you about the time... Grandpa. Yeah? You're going to say something, son?  Why did you, Grandpa? Well, now, son, you mustn't go feeling bad telling what happened at the trading post yesterday. Just because them folks say I... But they said you... You lied to me. They laughed at you and said you weren't brave at all. Golly, Grandpa, all this... Somebody's stopping outside.  Good evening, Ben. Howdy, mister. Jumpin', Judy. That big husky. Don't go to me. Don't worry. King wouldn't hurt an old friend. Would you, Father? King, did you say? No. Then you must be... Who is it, Grandpa? Bobby, tell your grandfather he shouldn't keep his old friends King and Sergeant Preston out here in the cold. Sergeant Preston and King? Oh, golly, Grandpa, you do know them. Uh-huh. At least why is that what he says? Come in. Come in. Thanks, Ben. Go on in, King. Please, Grandpa, tell King to do something. You said you were the only one beside Sergeant Preston. I could get King to do something. Well, then, tell King to lie down. Uh, he, uh, well, it seems so. Uh, lie down, King. He did it. He did it.  Look, look, Bobby, I've got a thought as to why Sergeant Preston come here. So you might be... You never were good at guessing, Ben. I suppose I'll have to tell you. Tell me. What you gonna tell me? Well, I came here to get your help, then. Oh, golly. Well, you could do it in what, Sergeant?  I'll need your help to get them. No, no, no, no. Jumping, duty fully, I'd kept my feet. I'll shut all this wouldn't have happened. Now you come to... But I'm not joking, Ben. Not at all. Not joking? No. Uh-oh. That's worse. You know, Bobby, he always acts like that, sort of making believe he might be afraid. Making believe, you say?  They get fooled into thinking it's a real thing, I reckon. Like yesterday... I heard about that, Ben. Of course you couldn't have any gunplay with Bobby there. Uh, see, see, now that's right. You know, if Bobby hadn't been along, I'd have... Leave that for another time, Ben, eh? Huh? Oh, yeah. So far you haven't said you'd help me catch those crooks. What about it? Oh, God, Sergeant Preston, you know he will. Won't you, Grandpa? See, even King is looking at you. I'm your king. King's asking you to help, too, Ben. Well, now it's this way. Fine, I knew you would. Now, put on your parkour and we'll step outside while I tell you our plans. By this time tomorrow night, I feel sure we'll catch the crooks who stole your gold. We'll continue our story in just a moment. Say, tell me, what was breakfast like at your home this morning? Was your family a breakfast-happy family? Did you enjoy tasty, heaping bowlfuls of Quakerpup wheat or rice? Say, if you didn't, you know what? I'd say you were missing out, that's what. That's because Quakerpup wheat and rice are the famous ready-to-serve cereals shot from guns. Yes, huge guns are loaded with only the premium wheat or rice grains. Then these choice kernels are actually exploded up to eight times normal size to make them bigger and better tasting. These king-sized grains are magnified, glorified, crispified. And most important, Quakerpup wheat and rice are good for you. They furnish added food values of restored natural grain amounts of vitamin B1, niacin and iron. So take a tip, don't miss out. Check right now. See if you have a supply for this coming weekend of wheat and rice shot from guns. If not, ask for both delicious kinds. Quakerpup wheat and Quakerpup rice. Now to continue our story. After Sergeant Preston had taken Old Ben outside and discussed his plan for capturing the crooks who had held up Ben and Bobby, the Mountian King returned to the settlement where they put up at the small hotel. The following afternoon, towards sundown, Old Ben arrived with Bobby at Weber's trading post. Leaving Bobby with Mrs. Weber, the old man went to the cafe where most of the townsmen gathered. There isn't Old Ben himself. Tracking down them crooks, Ben? Well, now, maybe I have, and then again maybe I haven't. Hans Weber at the trading post told me that old friend of yours, Sergeant Preston, went through yesterday, Ben. Maybe you should have been on hand to greet him and that famous doggy here. Well, I reckon Preston and King would understand if I didn't get him to greet him. Well, look, Ben, you still aren't sticking to that story about being good friends of theirs, are you? Yeah, Ben, give it to us straight.  Don't reckon I got to admit anything to any of you. Then I don't want it. Tell us straight from the shoulder, Ben.  Well, now, who said it was all the gold I had anyhow? Matter of fact, maybe those crooks were the ones who really got fooled. Never can tell. What do you mean by that? Yeah, what do you mean? Wasn't it all you had, Ben?  Well, looks like they were outsmarted after all. If you have the biggest part hidden at the cabin, I'm not saying it's really true, mind you. When you tell her something and say it isn't really true, that's when we know it must be true. How about it, boys? What did you do? Leave little Bobby out there alone to watch over that gold for you? No, no. Bobby's over at the Weber. He's going to stay there tonight on a visit. Don't need anyone to watch at the cabin. I've got a certain place there to hide things. A place no one could find without me being mad at them. Yeah, well, you were staying over for the night, so Ben? Oh, don't reckon so. Got some things to do early in the morning out at McLean. Fact is, I'm starting back to the cabin right now. Just dropped in to get warmed up a bit before starting. We'll see you all again soon. Come on! So long, Ben! Bring in all the troops, you cat! A short time after Ben left the cafe, a rough-looking man who had been sitting alone at one of the tables got up and nonchalantly made his way toward the door, without attracting the attention of the other men. Once outside, he hurriedly walked to the edge of the settlement until he reached a small cabin. He stopped for a moment, looking back to make sure no one had noticed his haste. Then he opened the door of the cabin and entered. Hi, Duke. Aren't you going to stay a while at the cafe away? I changed my mind, Duke. You see, while I was in there, I heard something interesting. If you mean about Sergeant Cresson and the Monty's and that big doggy who's come to town, I already know it. But he hasn't got anything on it. I know that. If I'm not talking about that Monty, it was something else I heard. Well, what was it? That old geezer we took the gold from a couple of days ago came into the cafe. He was giving us the laugh by saying he's got most of his gold hid out there in his cabin. Well, well, you don't say. That is interesting. Where is old Goat Whiskey still at the cafe? Ah, he's going on home. But the short time ago.  I sort of hate to have to do... But the kid isn't there tonight, Duke. He's with the Webbers at the trading post for a couple of days. Might be a cinch for us to get that gold. Yeah. Except for one thing. What's that?  Even if we did away with the old man, they'd be on our trail in a day or two. I thought of it. But it started to snow higher outside. I bet he'd cover any tracks we'd make. We could go out there without the dogs and sled, get that gold, finish off the old man and come back here to hold out and not be in the wiser. Yeah. Yeah, we could at the... There's no time like the present to get moving. Come on, let's go. Meanwhile, Sergeant Preston and the Great Dog King waiting outside in the shadows had observed old Ben leave the cafe. Still keeping in the shadows, the Monty and his dog followed to the edge of the settlement, where Ben turned off on trail that led to his cabin. Though a swirling snow had begun to fall, Sergeant Preston and King waited patiently. Finally, two men whose faces and figures were indistinguishable because of the bulky pockets they were wearing trudged along the main street and then turned off on the trail taken by old Ben. King standing beside his master immediately sensed the two men going past a short distance away meant danger. The massive dog had felt Sergeant Preston's fingers tense slightly as they rested on his back. They momentarily expected to hear an order to attack. But none came. Yet King's hair bristled and instinctively a low growl started deep in his throat. Quiet came. Easy thought. Couldn't be going far without dog sleds, King. Those are the men we want to follow.  Meantime, Duke and Rad, unaware that Sergeant Preston and King had seen them, trudged along slowly in the snow. The wind blew the falling snow in their faces and made it difficult to follow the trail. Finally, they approached a remote cabin and noted the glow of light shining through its window. But told them old Ben had reached home. There's his cabin, man. Yeah. Now you wait here. I'll go look in the window and make sure he's alive. Be right back. I'm getting cold. He's alive. Except when I was holding a pipe by the stove. Good. Come on. We are... Get out of the way. Now, you're kind of rough for callers, aren't you?  Close the door, Duke. Going to beat the band, isn't it?  Never mind a chatter. We came here for a purpose. You did? Well, what do you know? I guess you don't know who we are. I've got face. No, don't reckon I do, mister. Got a face and voices of yours, but for the life of me, I can't tell just where I heard him before. Now, let's see. Was it over...? We didn't come here to play guessing games. Don't blame me a bit. If there's one thing that gets me out of sorts, it's playing games. I'll recollect once when I was...  I never talked back to a gun, mister. I'm listening. You got gold hidden in this cabin. Where is it? No, however did you find that out, I wonder.  Where is it? Let me see. Just where is that hiding place? You know, the older I get, the more forgetful I become. It's a funny thing, isn't it? I'll plug the old coat and then we'll search a cabin. No, no, no. Don't be so hasty. Yeah, I reckon I'm beginning to remember where that hiding place is at that. Speak up then. Ah, a funny thing. The old man don't seem to be nervous like he was the other day when we held him up on the trail. So that's where we met before. You know now that I've come to think of it... Show us that hiding place, sir. Yeah, sure. Sure. Bitch. The seven of the four boards over there in that corner. My robot is acting up tonight, so if you want to see for yourself... That's like a luxury. All right. Got my loose boards here, Rhett. You gotta have to get up though. Yeah, Bobby usually has to help me lift them. Yeah. So it takes two. Sit down there and don't move or I'll let you have it. Sit down. Sure. Sure, mister. He's shaken now, all right. I'll help you, too. He's nothing to worry about. As Rhett walked over to help Duke and stooped down the loose and the floorboards, then slyly took a gun from inside his coat. At first his hands shook violently. Then remembering Sergeant Preston and King, he controlled himself. And grasping the gun in both hands stood up and aimed it at Red and Duke. Now! Now I've got both of you covered! What the... So you better drop that gun. Look, Rhett. I'm gonna shoot if you don't drop that gun, mister. I hope Billy comes... You better take a look at the window behind me, mister, and think again. I reckon you'll see a mountain standing there. Aiming at you right through the window. You see? This was all planned to get you to come here. It's a trick, Rhett. Ha! Yeah! That's right! And it worked, too. Yeah. Well, the party of plan was that of Marty standing outside that window with a pointed gun. It didn't work. There's nobody outside that window. Hey! There's nobody outside! But there must be! He said he'd be sure to cut... Oh! As old Ben realized that Sergeant Preston wasn't at the window as he'd planned to be, he'd stare in a dismay at the crooks before him, and the gun wobbled into shaking hands. Meantime, King would run ahead of Sergeant Preston as they neared the cabin, sniffed the tracks of the men they were trailing. Coming to the place where they had stopped, his curiosity caused him to follow the single tracks made by Red when he had gone to look in the window. The light from the window and muckled voices attracted King, and reaching his front paws up to the low window sill, the intelligent dog looked inside. King's sharp ears caught the ominous tones of Red's voice. They saw him reach out his gun toward old Ben. The great dog instinctively knew the gun would spur out death-dealing bullets any minute, and he went into action. Moving back a short distance, he raced forward and sprang. King run straight from Red, grabbing above the gun arm and knocking the gun from the lamp. Help! Help!  Do something, Duke! I'll get him down! No, I won't! This will settle you, old man!  He'll live, I think. Watching, King. Ben. Ben, are you all right? Oh, I've got me! Sergeant Preston, you've got here! Yes, Ben, but almost too late. King ran on ahead, and I came as quickly as I could. King saved my life! Come right through the window like a thunderbolt! This eye took a tumble! I saw through the window how you kept one of them from shooting, King. It was a brave thing, Ben. You might have been shot. Shucks, Sergeant! Why recollect the time, right? Promise one thing, will you, Ben? No more tall stories. Right, King? Now we'll take your sled, Ben, and get these two crooks into Dundee. Go get it ready, please. All right, Sergeant. Come on, you two. Let's go. The following afternoon, a group of men stood around the big glowing stove in the trading post. I tell you, gentlemen, every word is true. Sergeant Preston himself told me to stop. Well, maybe show hands, but it's hard to believe that old Ben... Oh, here they come now, and also King and little Bob. Oh, hello. What a gathering you have here today. Ah, that is so sad. They have come to find out if it is true what you told me about old Ben. I don't believe in lying, Sergeant. Stop! There! You see just like I said. And my grandpa is a friend as Sergeant Preston's and King's. So there. He certainly is, Bobby. He stood up to those crooks last night and saved King's life. I asked for Ben's help in catching those crooks, and he didn't fail me. Well, I'll be doggone. I guess we've got to apologize to you, Ben. You're all right, amen? Yes, sir. Tell us, Ben. Weren't you scared, any? Well, no, I got to admit I wasn't much scared for a bit. But we set out to get the crooks to drop me. And by gun we did it too. I'm a bag of gold on one of them. Gramp is about the bravest man I ever told. Catching those crooks wasn't anything to some of the things he's done. Isn't that right, Gramp? Well, now, can't we think of it? I do recollect once over and sell it. Seems like King's trying to tell me something. Good be, Ben. Maybe he remembers a certain promise. Huh? Oh. Yep, smartest dog I ever knew of. What were you going to tell about when you were selling it? Oh, forget it, Bobby. Any stories I have a mind to tell, I'll let King tell him for me after this. That's the wisest decision you ever made, Ben. But at least you can tell how you helped King and me close the case, eh, King? In just a moment, Sergeant Preston will give you a preview of next Monday's program. Discover why Quaker popped wheat and rice win the praise of so many Hollywood movie stars. Try wheat or rice shot from guns yourself at breakfast tomorrow sure. These giant, tender, king-size grains are premium grains. They're never sold in bags or bulk. Always look for the big Quaker red and blue package to get the original, crisp, fresh, Quaker-puffed wheat and Quaker-puffed rice. These radio dramas, a feature of the challenge of the Yukon Incorporated, are created and produced by George W. Trendle, directed by Fred Flower Day, and edited by Fram Stryker. The part of Sergeant Preston is played by Paul Sutton. They have brought to you every Monday, Wednesday and Friday by Quaker-puffed wheat and Quaker-puffed rice. The breakfast cereal shot from guns. Listen next Monday when Sergeant Preston and Yukon King meet the challenge of the Yukon in the adventure of potluck killers. We've a mighty exciting show for you next Monday. It begins when King saves a girl from drowning, but that's just the beginning. Before we leave that girl, I'm captured by six murderers. And if it hadn't been for King, well, it's a critical moment when they decide to add me to their list of victims. Don't miss this exciting story next Monday. Till then, this is J. Michael wishing you goodbye, good luck and good health from Quaker-puffed wheat and Quaker-puffed rice. So long. For a delicious hot breakfast, eat Quaker oats. The giant of the cereals is Quaker oats. Yes, the giant of the cereals is Quaker oats. Delicious, nutritious, makes you feel ambitious. The giant of the cereals is Quaker oats. Say, boys and girls, do you want to be a star someday in sports and activities? Then start on good Quaker oats breakfast tomorrow because nourishing oatmeal gives you more growth and endurance than any other whole grain cereal. Still less than one penny of serving. Quaker and Mother's Oats are the same. This is ABC, the American Broadcasting Company.


Welcome to the Network Engineering video blog. I am your host, Michael Crane. In this video, we need to add all the changes we've been making to the Cisco Router node class to the other node classes. The quick way to do this is to copy and paste the code, but that would result in a lot of code duplication, which is a bad thing. So we need to do some code refactoring and add a class node base class that has all the similar properties, methods, events, and fields defined in it, from which the derived classes can inherit and extend. We also have to make changes to the xAML user control to support the new code behind for the base class changes. So let's get started. OK, so first let's look at the original Cisco Router node class and look at the functionality we need to implement in the Cisco switch node class and the Xena test node classes. We just basically, we just need to copy the code from this class right here to the switch node class, sorry, the VB class, and the test node class. And if you remember, we've been following along with the previous videos, we added basically as just the drag and drop functionality, which was quite a pain to get going. So it had some mouse events, there was like three different mouse events associated with that, and these are going to be the same for all the nodes. It's using, we're just moving around a rectangle for all three nodes. So this UC, where is it? Sorry, for jumping all around. Yeah, so this UC node will be the same. It's just the rectangle and the XAML, we'll look at that here in a minute. And this other stuff right here is just more duplicate code that needs to be just copied over. So like that each node is going to have a node type, a node index, and each node is going to have this point origin. And I think I just deleted this stuff out. Well, we'll look at that. Oh yeah, you can see it over here. We'll look at the changes here in a sec. Okay, so we just need to add the get location functionality and the edit node, delete node, and the events that I just talked about. All right. I mean, like I said, I could just copy and paste it, but duplication of code is not a good thing. So what I did is I created a class node base class. All right. And as you can see there, it's not diffing it because it's a brand new file. You can see add right here. So it's just going to add it to our repository. And this basically has all the code that was highlighted in red copied over to it. Yeah, so here's the two, the node type and the node index. Yeah, this is an abstract class. An abstract class means it needs to be inherited. And originally I put must inherit up here, but I was having problems with that. It kept telling, it kept giving me an error about the property, the name property in the XML. And I don't remember what the error was. I just moved on. And just to let you know, it took me quite a few hours to get this working because I'm not real familiar with the WPF coding. And I wasn't really sure how to implement this inheritance. And by the way, in case you're wondering, I was following along this little document right here, the inheritance basics and visual basic. And it's an over. OK, little article, must inherit. That's what I was trying to add. And this wasn't working. And here it talks about it being an abstract class. This is an abstract class for sure because this object right here is actually defined in the XML in the derived class. So this is the base class. This isn't the drive class. We have to, when we drive the class from this base class, we have to populate this variable right here, or it's just going to get an all pointer exception or whatever Microsoft compiler spits out. It's like a nothing or something. But yeah, so really, it should have that must inherit, but it wasn't working. So I took it out and it fixed it. Someone knows why. Let me know. I'd be interested. So the duplicate, so we just need to add this to all the different node types. Let's look at this class node real quick. Just copy those things over. This is just setting the point origin. The get location was copied over. The edit node, all this stuff should be very similar. If not, we can override it in the derived class. I don't think this edit and delete actually worked yet. But what's nice about this is when we do go to fix this, I just need to fix it in this one file. I don't have to go to each individual node and fix it. And I'm sure most of you understand the purpose behind a base class. Okay, and then all our events, right? And this is just removing the node object around. So yeah, so that's everything I put in this base class, which is basically all the red that I cut out of the original router node, the Cisco router node class that we've been working on, okay? Okay, so let's look at, so now let's look at what the new Cisco router node class is. And as you can see, it's pretty small. I just noticed something, this doesn't need to be in there at all. So yeah, let me go fix that real quick while we're looking at it. I just missed this, this is actually already in the base class. I'll close this guy, that's the class node. Yeah, so we'll double check, but yeah, so all that stuff's right here. Alrighty, so let's go into the router node code behind, and we'll just delete this guy out. Now it's even smaller. Yeah, so anyway, yeah, this is the new router node class. And then you can see right here, Cisco class router node just hasn't changed, but now it just inherits class node, which has all the functionality we deleted out of this file in it. Okay, so another thing we have to do is we have to populate the base class variable Dnode with our UC node object reference and our UC canvas object reference that is actually defined in our XAML. Right here, here's the UC canvas and here's the UC node. So when you're accessing it from the drive class, you can just use UC node and UC canvas because it's part of this Cisco router node object when it's instantiated, but the class node base class right here doesn't have access to it until you instantiate or derive the Cisco router node. Okay, when you're initializing a base class, usually just pass the parameters in when you instantiate the new drive node. So I wouldn't be here. Actually, it would be in the class node, you would say no and then Dnode and D canvas, right? And this isn't proper. You'd say, let's say by rough Dnode as object and the same thing for the D canvas, right? But in Visual Basic, that won't work because the only time you can initialize the base node class is right after this new statement. So if you try to go under this initialize component and say my base.new, you're gonna get an error and it'll tell you it's only valid as the first statement in an instance constructor. So in other words, it can only be up here. So if I wanted to pass this UC node variable and UC canvas into this, I could only do it up here. And the problem with that is they're not actually instantiated these two variables until you run this initialize component. So it's kind of a chicken and an egg thing. It kind of had me scratch my head for a bit, but so I just said, okay, fine. I just, what I did is I just passed them in after this initialize component just by saying my base.dnode equals me.uccanvas. And it's like passing in a pointer, I guess, right? It's a reference to these two objects that the base class is able to use, okay? I hope that kind of makes sense because this is important to populate these variables down here, otherwise this will not work. This inherits class node and passing these references to the base class. Those are the only additions to the Cisco router node class, all right? And actually that makes, we might as well look at the other ones while we're at it. So we'll look at the switch node and we've got to take this junk out. Yeah, as you can see, these classes are much smaller and if you're wondering what the purpose of this is, there's a couple of them. One, all the functionality that's similar to the nodes in one file. So I just need to edit one file to add new functionality to all our different nodes. In all the drive classes, this is where you add the custom functionality. We want the Xena test node code behind. Delete this out, save this, make sure it builds. Yep, and we're running it to make sure it works. Okay, so add a router, all right? That's good, add a switch, that's good. And we'll add a test set. There we go. Make sure we can add links to them all. So router to switch, add another link from switch to Xena, all right? Can we move them? Yes, we can. Okay, and that was just a quick test to make sure that change we made didn't harm anything. That was pretty sure it wasn't gonna break anything but in ever now, right? Okay, so we already looked at the class node base class. Okay, so I had to make some changes to the XAML code as well to support this new base class. And one of the things I should show you in this base class is, so this base class is, okay, this is its name, but it's inheriting the user control, right? If we look at the code behind, yeah, so this is its name and it's inheriting class node which class node is, of course, inheriting user control. So let's go take a look at our XAML. Maybe this diff would be good here. So let's go back here, XAML. So as you can see, yeah, so it was used control but now it's a class node. We had to define it as it's a local class here. So now we've defined a local class node as the derived user control class. I hope that makes sense. I hope I'm not confusing everyone. Let's see, what else has changed in here? This right here, I just deleted it out. For some reason, Visual Studio keeps popping just unused junk in there, so I just deleted it. So one of the things that you should know that I ran into is you can't really, or at least I didn't see a way to inherit the XAML code. So in other words, I couldn't really create a base class XAML file and inherit it into another XAML file. And I kind of did some rating on this and I think I'm correct. If someone knows different, then they can let me know. These XAML files, at least the way I'm using them are specific for the drive node objects look and feel. So it has the height and width is gonna be different between the router node and the switch node and the test node. And I changed some of the margins around. I mean, there is a lot of duplicate, like all this stuff is duplicated right here and I guess it would be nice to put in a base class type file, but I don't think Visual Studio supports it. Like I said, if someone knows, they can let us all know, right? So yeah, I was just messing around with the height and width these guys. That has not a lot to do with their base class. And right here, I just instead of having one long string, I just kind of stacked it right here to make it. I also changed the alignment to center for the text to line it up in the center of our rectangle, right? And that's about it. So basically the biggest change was this user control to our new class node class in the xAML. Okay, and we can take a real quick look at some of the other xAML files, but they're all pretty much gonna be identical. See, right, see these guys right here didn't have any of that code that was in the router xAML that we've been working on. So this was a big copy and paste. Because the code is duplicated in these xAML files for sure. But the image source is a switch, whereas in the router, it's a router. And of course, the margins are different, foregrounds change. So there's some changes, this is customizable or this is being customized. So it makes sense, at least to me, that these files are only related to the drive nodes and not the base node. And let's go look at our test node, but it's gonna be pretty much the same. It's, I did leave this drop shadow effect in there. So that's different from the Cisco nodes. And of course, the different images, different margins and the text color is different. If I they call it foreground, I don't know. I don't know why they just don't put text color or something instead of foreground. But anyway, I digress. Okay, so let's go to the main window and this is gonna be very interesting. This is another copy and paste. So I didn't remove this code right here and re-added. What happened is, is I just, I made this guy a capital R on the router instead of a lowercase R on the router. I did it because I thought it looked better, right? So basically I just copied all this code right here. Actually the code from here down or from here to here, I just copied that and pasted it in the switch and in the test set. And I didn't do anything to link code down here. And oh, you can see it right here where I pasted it. I also made all the Zenas capitalized. That's why you're seeing changes right here. Otherwise there wouldn't be any changes there at all. And what started me on this path was the switch right here. Switch is a keyword in Visual Studio. It's probably switching a variable, right? And I was basically overriding it with this local variable. And I thought, this is gonna cause problems. One thing I kept capitalizing, switch because it was capitalized. I didn't look at it, but I'm guessing at it. Anyway, I just changed it to e-switch because it is an ethernet switch, right? And that, my friends, is it. I can't think of anything else. Don't forget, you can support the Network Engineering video blog by donation using a credit card and PayPal or by purchasing products at the Moxall store. Details and links are in the description under this video. Well, that's it for this video. If you liked the video, give it a big thumbs up. That helps and hit the subscribe button. That really helps. If you have any questions or comments, post them in the comments under this video. Thanks for watching and I'll see you next time.


If you're new to snowboarding and are looking to buy your first setup, the Genie could just be the board for you. Designed and built to smooth the transition from beginner to intermediate rider, this go anywhere, ride anything board delivers that perfect balance of confidence, inspiring feel and all terrain performance. Built around a predictable, true twin shape, the Genie utilises the unique, easy bevel bass profile. This innovative design adds a convex profile to the bass at the contact points, making it almost impossible to catch an edge. Although the Genie is soft, thanks to its versatile flat top profile, which features a flat section between the bindings with rocker zones just outside the feet, it still delivers great performance. So once you really start to get your riding wired, it's not going to feel out of its depth. Now internally, the Genie is built around the durable and responsive 900G Superfly 2 core. This innovative wood core features Burton's advanced squeeze box low profiling, which reduces the thickness of the core between the feet, creating a softer, more playful overall flex. Now to keep that playful and confidence inspiring overall ride, Burton utilises their softer bias glass structure layers. These allow the board to absorb terrain changes, letting you concentrate on technique. Finally, to give great performance in all conditions, the Genie features a low maintenance, easy repair, extruded bass. Now to complete the setup, the Genie comes complete with stiletto bindings.


Thanks, everyone for being here today's Monday, so before we get started back into awesome slides and content we have some class things to discuss. Okay, so there's been some questions about what exactly the gradient breakdown of each of the project's homeworks midterms is going to be. So what we're going to do, the weights are definitely going to remain the same. Basically the idea was project one and two were supposed to be very simple and so you should get full credit on those. Turns out for some people it was more difficult because the submission system, whatever. So the basic idea is what we'll do is we'll take whichever is the higher of either projects one through five each have equal weight meaning they both are 7% each or basically one and two are the same weight. They're considered kind of as, you can consider them as half, they're half, they together make one project and then that means each project's 3, 4, and 5 bump up and they're 8.75%. So we'll do this whichever one is higher that will be your project grade. So you don't have to worry about that but if you're worried about going to cuss with the class or you want to calculate out what your grade could potentially be or if your maximum could be this is what you should keep in mind. Questions on that? So for the last project I had like, I didn't get three correct but I did get like 8 out of 15. But sometimes like I think test case four it would mess up with the syntax. Like it didn't show up on the test cases for the grading but it did show up on my own. Then I would probably not complain about something like that. So would I get the 50% reduction or do you like add... So whatever the grading, whatever is on the submission system, right? Yeah. So that's fine. Yeah. Okay. Awesome. Yeah. Any other general questions like that about... So then how does your score be proportional based on... So we pretty much actually have the project for grades. Most of them we'll post them later. We're kind of waiting today if there's any late submissions. But yeah, the average was like a 68 of those that submitted. So that should be pretty good. Any other questions about this grading policy for project, for grading projects? Yeah. That's true. Hi. Hey. Hey. What are you guys doing? Hi. I just wanted to say thank you for the extra two days. Oh. You're welcome. All right. What's your name? I mean it was your fellow students. All right. Anything else? That's a weird comment. Yes, thanks. Anything else? Nothing else. It's pretty clear, right? So you should be able to go home, calculate exactly what these two numbers are because these are grade or one. If you do the math wrong, it's not my fault, right? Okay. All right. Any questions on this? So let's take care of the first issue. Let's talk about, I guess we could do homeworks next. Okay. So homeworks, I said at the beginning that there would be six homework assignments. But when I was looking at the schedule, we really only had time for five homework assignments. And I know it's a huge bummer to all of you to miss out on that six homework assignment. So what I was planning on doing is you can do, I will issue a six homework assignment. If you submit that, the motion you get out of it is 70 out of 100, but it will replace like your lowest homework score. Got it. So if you submitted a homework late or missed the homework, you can kind of use this as a little replacement. You have to actually do the homework, right? Oh, you said the motion. Get that. So if you get 70% of whatever you submit. Okay. And obviously it's not greater than anything. It won't affect your grade, right? Questions on that? Comments? More comments? No, no more comments today. Yeah. Any questions on the homework? Do you want more projects? The project's a lot. Any questions on homework? All right. So done with homework? Okay. So now about projects. So the TA has been getting inside my head and he thinks it was a good idea and I think it's a good idea. What we'll do is you can submit either project three or project four late, either one, only one, and you can get at most 70% of whatever you get. So you basically have from now until project five is due to resubmit one of those, whichever one you submit latest is the grade you will take. Yeah. So I know a lot of you are really close on getting one of those to work. So get it working. Obviously we'll check for activity violations, so please don't take the easy way out. Yeah. So if you do the work, you will get points on one of those projects. So questions. This should be pretty much everything you need to know should I drop this class from now until before, right? Any questions? Nothing? Yeah. If you resubmit project three, it's no. And then with the 70% score? It won't, it won't, it won't, you're having to get lower. No, no, yeah. It's whatever is higher, for example.  You submitted somebody else's code and then we found it and then now you've done bad things so it could deal with that. I don't want to deal with it, so don't do it. Yeah. Basically if you've got 70% on either, on both of them already, it wouldn't stop at 80%. Exactly. Yeah. I will assign next homework and next project on Wednesday. I want to give you guys at least a little bit of a breather. So this way you can send the sign to finish project three or project four, whichever is your lowest, and just get it done. Then you can have all semester to focus on project five. Yeah? If I wasn't able to turn in project three and I turned it out, do I get points or notes? You'll get whatever to this thing. So yes, you'll get as most 70% on whatever that submission is. But you can't do that for both project three and project four. It's an exclusive war. Yeah. On the fourth, this upcoming Wednesday. We don't have class next Wednesday. It's a better day. Yeah. Is there a special submission process for resubmitting? No. Just submit through the submission site and we'll get it. We'll take your latest one. So if you want to try and do both to see whatever is maximum by the date that project five is due, which I think the last week of class that Wednesday, just submit it. Submit the one that you want very last. Any time from now up until project five due date. So project five is due the last Wednesday, the second. So the second at midnight will be the due date there. So do it early. Get it done by the way you know where you stand in the class and everything is all good. More questions? Yes. Oh, sorry. We'll go here and then there. Yeah. What's Lambda calculus? Do you really want to get there? Lambda calculus is awesome. It's going to blow your mind. I'm super excited to start it. We'll probably start it next week. What was that? Yes. I don't know. I can't consider that. What do you guys think? Is that fair? Yes. What? Should you get extra credit for submitting it late? No. I don't know that you're a really unbiased audience right now. I guess so you could get more than above the 70% reduction if you got 105% but we take 70% off that. I'd say yes. That's, I guess that's fine. It's 70% of five. I don't know. Something. Anything else? Any questions? Okay. Any other general class stuff about grading or grades in general? Yes. So say for one of the projects if you had just started it late but got below 70% Just resubmit and then you'll Just resubmit. Yes. All right. Good. Now we've got to get on some material because we clearly have to get the Lambda calculus very soon. De-scarify it for everyone. All right. Two, pass by name. So here we're talking about pass by name semantics for function parameters. Yeah. Wait what? It's a type checking problem right? Yes. There's more of a five type type. Not like a job or something like that. What's the difference? So in Python we generally don't declare any variable before. In general it can be used in a particular... What are types checked in Python? And they're in Python experience. So what does that mean at runtime? It means like whenever a type is on the right-hand side against the left-hand side. So almost kind of. So in Python or JavaScript or a lot of scripting languages like Ruby types are checked at runtime dynamically. So the interpreter has metadata that says hey this variable is declared as an int and this variable is declared as a function. So if you try to assign them before it does the assignment it checks the types. Then when it's executing and if there's any error it exits. So did anyone here execute the programs that they were trying to type check? No I hope not right? That doesn't make sense. We didn't really talk about how even the semantics there were. So in that case what you're doing you're static type checking right? So you're type checking it without executing the code beforehand after parsing. So in that case you did just what Java or C or C++ does is a static type checking. The difference is we also we had implicit variables in all language which meant that we didn't have to declare something before it was used but that doesn't mean you have to type check it at runtime which is what you saw and what you implemented. Which is why languages like OCaml and ML and Haskell are kind of fun and cool because you don't have to declare types but it does intally mill their type inference to infer the type throughout the program and check that statically. So you get the fact that you don't have to declare types but it will do the type checking statically so it will find type errors for you. That was an interesting one. So in project four we get a type checker, yes. I hope you did. Alright, so what are three, we talked about three different variable parsing semantics to functions. What are those three? What is it? What's the full name of what you're talking about? What is the name of the semantics? Somebody want to help me out? What is it? Passed by name. What was the other one? That's one. Passed by reference. Passed by reference. And the third? Passed by value. Passed by value. Yeah, going back to classes. Alright, and I said passed by name so that's not it. That's the most confusing answer. Okay, so we've been looking at pass by name semantics. So what are the semantics of pass by name? So the formal parameters are replaced by the actual parameters we're going to replace. Text-wise. Yeah, text-wise. So it's as if you textually replaced all instances of the parameters in the function with whatever you pass into the function. So let's look at an example. So this is C code. So here we have a function p that takes in an integer y. It sets a local variable j to be y. It increments i. And which i is this referring to? Global. The global i? Are we using static scoping or dynamic scoping here? Static. Static, how do you know? You said the rest of the class is static. Yeah, because I said it. It's just like the type rules, right? It's that way because we said that that's how the type system works. And just like this. So we said from here on out pretty much all the examples, at least in class, will be static scoping. And if there's any question, it'll be said and specified on a midterm perhaps. OK. So we take j is equal to y. We increment the global i. And then we return j plus y. Seems pretty straightforward. Next we have a function q, which has its own local variable j, which then sets the, which i is this? Global i. Global i. And then crates out function p called with what as the actual parameter of p? i plus j. Can I do that? Y. Type? Same type. Same type, what are the types? Integers. Integers? OK, that's one reason why, yes. That's another reason. Yeah. So you have i accessible to y and j. I have accessible to i and j in the scope of q. Yeah, that's one reason. What's the third? What was that? Past by name. Because of past by name. No. So because the semantics of function invocation says that we can call a function with expressions for each of the arguments. So here we're saying hit the first parameter to this function p that we're trying to invoke. The actual parameter is the expression i plus j. OK. And now we have a function main where we just call q and then return 0. So if i was running this as a c, so is this a valid c program? No. Why not? I know it was you. Why not? Because I'm going to use past by name. But I didn't ask that. I asked if it's a valid c program. Yeah? So what's it going to output when we execute this? As a c program. So what kind of semantics does c have for function invocation? Past by value? What is it? Past by reference. How does that past by reference? But it's not. C. C. Right. So c is only past by value. C plus plus you have the option of doing past by value or past by reference. So this is past by value. What would be the output here? There's one print statement. So it outputs 6. So what gets passed into p with past by value? 2. 2? And then it returns what? 2 plus. 2. Which is? 4. What's the elementary school teacher feel like? Awesome. 4. And then what gets printed out? 4. 4. 4 gets printed out. Right? So does the value of y does the parameter that we pass into p change? Right. So what about past by reference? What would the difference here be? There'd be no difference. Why? We don't ever use j, which j? So the j in with u, that value would change to before. And that's the difference. But we don't ever access that later, so there's no difference. So if we were to access that j later, then it would look different. Does this, what changes this j? If you were to pass it by reference. Am I passing j in as p as the actual parameter? Right. Yeah. What are the semantics of passing an r value in by reference? That's a good question. What are the semantics of passing an r value in by reference? So what do you mean by r value? Right. So why is this an r value? I guess. Because why? Because it has an operator. Right. So we're taking two l values, we're adding them together to get a value. Does that have a location associated with it? No. No, we can't draw bots for i plus j. We're not assigning it anywhere to anything that has a location. So I guess that was a really tricky question. So you can't actually, this wouldn't, this would not be allowed with reference semantics. Or just with pass by reference semantics. So the compiler would say, hey, I need an l value here and you're passing in an r value. So I'm not going to compile that. Okay. So with pass by name semantics. So I'm going to guess what the output's going to be in pass by name semantics. And include accompanying guesses. Fault. Fault. Error. Ten. Thirty-two. Twenty-five. All right. One thing that may help us to think about is let's, remember we're thinking textual replacement here. So let's think about what is this function p that's going to be executed where we replace all instances of what with what in the function. Replace what? Why with i plus j? Replace y in function p with i plus j. Right. So that's the semantics here at pass by name is we want to replace all the y's with i plus j. So you can think of it as, as we have this function call and we say in j is equal to i plus j, i plus plus, return j plus i plus j. So, but what are these j's and i's referred to? Which, so I should say which i does this refer to here? Global i. Definitely. Right. So remember we talked a little bit about on Wednesday that when you do pass by name reference, the scope of wherever the function is involved that the parameters are used. So wherever those are bound to, so here i is bound to the global i. What's j bound to here? The local j which has the value two. Right. So it's not going to affect the j in the function. So we just need to keep it straight in our heads that this i plus j returns, refers to global i and global j. So, if I compiled this with a special version of GCC that allowed pass by name and I ran it, what would the output be? I don't know. Truthful answers. I was waiting for somebody to raise their hand. Nobody wants to raise their hand? Yeah. Well wouldn't i just have a value that was already in memory of this, where you get the sign it in and you can just go in and my view sign is zero. Right. We assign i zero right here. So that's good. So now that you know that i has the value zero, what's going to happen? So on this line, what's the j that's local to the function p? What is that j going to be? Two? So it's going to be i which is zero, j. And then i plus plus is going to be what? Increment i to be one. Now we're going to return j. So which j is this? Two. Two. The one that is local. It's going to be two plus i plus j. What's i plus j now? Three. Three? So what's this function going to return? Five. Five. So why do you return five and not four? It's going to bring you down. Yeah. Because i is reference to the global function. Right. So and what happened to i during the function call? It got suspended by one. Right. So this function that we called is using this global bit of data that we're using our expression to pass by name. So that messed up, that changed what our expression i plus j was. Right. And depending on if i was incremented more here or the orderings of these, if i was, the i plus plus was the first thing that happened, that would change what value we got back from this function. Does this seem like an easy way to code? Yeah. If in q we set i equal to one way or here. So if i was one, how would that change things? So it would be one plus two would be three. And then it would increment i again. So i would be two. And then it would be three plus two plus two would be seven. Too much math, guys. Yeah, that's a really good example. That's why you need calculators. So yeah, pretty crazy way to code, right? So this is why we're not programming anything because I have this pass by name. So let's look at another aspect of pass by name. So here we just have a function foo that takes in a parameter called test and just returns ten. And then we have a function made that says in a is equal to zero. It says integer b is equal to foo a plus plus. And it prints out the values of a and b. So in pass by name or pass by value, what's the output here? What's a going to be here when we get to this print out? One. And what's b going to be? Ten. Ten. What about pass by reference? By oh no. It would be zero ten. Be zero ten? I think it would be. Yeah. That's a tricky question of what is a plus plus return? I think it's going to use the value of a. So use a as a reference. Pass that in but it doesn't really matter if you get ten back. And then it should increment a. Zero ten. Zero ten. Why would it be? Oh, sorry. One ten. Yes. Definitely. So a is definitely going to get incremented in pass by reference. Pass by reference or pass by name? In pass by reference. So yeah. So now the question is pass by name. What's pass by name in a good? Zero ten. So why zero ten? Because it's not actually getting a value from a plus plus. It's just looking to replace it so it never uses it. Right. So remember we're doing textual replacement now. So if we look at the function foo and replace everywhere that parameter test is used in the function with a plus plus. Where's a plus plus? Where's the parameter test used? Never. Never. It's never used. So we're never going to evaluate that expression.  Yes. Clarify. Yes. Pass by reference. Yes. That actually works. Yes. I believe this would compile pass by reference because it would use a. Get the reference to a. Pass it to the function. Nothing a would change and then it would increment a. Yeah. So pass by name like you literally copy and pasted the parameter. Exactly. Exactly. And so because of that, right, because we're never using that parameter test it never gets evaluated. So it could, in this case it would never, a would never get incremented. Yeah. Let's go to it. Inside foo if you have like a use, would it increment a inside main? So. I'm assuming not. Right. Is that a question about pass? So the other thing is, is this a scoping problem or a variable semantics problem? Yeah. So it's scoping, right? So that's, so this is just what happens at function and location time. So before we even get there, before we run the code, right, the compiler has already linked up all the variables to their locations. So we tried to use a in foo. It would say, hey, a is not defined with static scoping. But if you did it with dynamic scoping, that would make for a very interesting problem. Yeah, you guys are really good at that. I'd be a generation through questions. More questions? There's other hands over there. Cool. Okay. Then if I run this, so I'll get them out of zero and ten. So it's actually a really cool kind of byproduct here. So this is essentially some languages have what's known as lazy evaluations. In this case, function parameters aren't actually evaluated until they're used. So in this case, you can pass stuff to a function that may or may not get evaluated. Which could be, can be cool. You can have infinite data structures in Haskell. You can make an infinite list. And the list is only generated as much as you need. So it's kind of fun. But it really messes with your mind. Okay. So, is this just in some esoteric domain that you have to learn because I tell you to? Yes, that's the answer for everything. But the other thing is how could you, let's say you wanted to make a language, could you implement this behavior in C? Could you implement, so we saw that pass by reference semantics, you can implement using pass by value semantics by using pointers. Right, so you're still copying the pointer, but the pointer is through an address so you can change what something, the value that something is outside your scope with pass by value. So can you do the same thing with pass by name? Maybe if you made it by sentence. What was that? It was just a macro. If every function was a macro, how would that help? Oh, so then you could replace the, yeah. So that would be, so macro is right in just textual substitutions of function calls. Then you get into some issues though, I think would run into the problem of if you tried to define a function like this called like a plus plus here, where does this plus plus actually go in the actual evaluation of the function? And is there any scope in conflict between the parameters that are defined and the local parameters? So that might be tricky with local scope. You could maybe get away with it. So what was it that you said? What do you mean peace? So like if we were to pass in an expression that was like a plus b instead of passing in. Yeah, so actually what if we wrap, so if we think about it, right? In pass by name, every time we want to get a value from one of the parameters we have to execute something in that context that called us, right? Whatever was passed to us. So if we basically turn those into little functions and every time we want a value to call that function then it can generate a value for us and every time we use it we call that function again so any side effects get properly replicated. So we can go back to our other example and do this completely with functions in C. Now it gets a little tricky. We have to kind of change some variables around but the basic idea is here. So here we have the global I again. We have a function P which takes in an integer Y. Okay, so this is all the code that we already saw. So we have Q, blah, blah, blah, blah. We have main, we're calling Q returning zero. So this is on the left-hand side. This, yeah, you're left. That side is all the code that we already saw at pass by name. So if we replace all of these parameters with instead functions then we can actually get the same behavior. So we have to create our function Q and Q is pretty much the same. So sorry, this is a little jumbled, but... All right, where are we at? Okay, let's look at it. So we need to kind of create this function I plus J to capture this semantics here of this I plus J. And so what's this function going to return? It's going to return, which you can tell from the type signature. It's kind of a name, right? It's going to return I plus J, right? So this, the I corresponds to the global I and the J, essentially we've lifted this J instead of being local to the function Q. We're lifting it out to be global scope. Yes, you could, but we're simplifying things a little bit. That would, yeah, that would complicate things. Okay, so this function I plus J, when we call it, what does it return? I plus J, can you call it multiple times? Yep. And every time you call it, what's it going to evaluate for the values of I and J? Yeah, the global. The value of the values in the global I and J. So if anybody messes with that global I, the next time you call this function I plus J, that's going to be reflected. So we can write our function P, where instead of now taking an integer Y, now we're going to take in a function that takes in zero parameters and returns an integer. And we're going to use this every place we use a Y, we're instead going to call this function Y. So we'll set our local J to be the result of calling function Y. We're going to increment I, and then we're going to return Y, J plus the function call of Y. So is this valid C code? So then what did I pass when I called P? What am I passing in here? What was it? I think somebody just said it. Yeah. Yeah, function pointer, right? What's the type of this function pointer? It's a pointer to a function that returns an int and takes no parameters. Yes. So thinking about it like a function level, right? So what is it? You said it's, what are we talking about type two functions? There's a whole homework assignment on it. Yeah. Like the return type, the number of parameters. Right. How many parameters? Zero. Zero parameters, and what does it return? An int. An int. There we go, right? So we're passing in a function that takes in zero parameters and returns an int. Right? So in the return type inference, you calculated what the type of a function is. And this is here. Here we have a function P that takes in a function as a parameter. And every time it wants a value, it calls that. And it evaluates the current value of i plus j. So is this valid C code? Yes? No? Maybe? Yeah. That's valid code. And what happens when we run it? What's going to be output? Is that it? Is that what I'm saying? I love it. So it has a mumpel? Five. Five. Is it any different than pass by name semantics? Is the output any different? No. No, but that doesn't mean it's not different. So let's rephrase it another way. How is it different from, how's the program on the left different from the program on the right? Longer. That is correct. It's a valid statement. Does that mean it's more complicated? So yeah, so here I'm using only pass by value to emulate pass by name semantics. So this is to show you that it's not impossible, right? This is just, these are kind of just different ways to express things. But it's up to you as a language designer to specify what these semantics are so they have very well-defined semantics. And it's up to you as the programmer to understand them and to know what they mean and what the different types are and what that means semantic-wise. But under the hood you can implement, you can emulate either of them, so it's kind of cool. Questions? Pass by name? A pointer to function. Yes. It takes from there. Correct. That takes in no parameters where the void comes from. It returns an int. So this is only, the only thing is here, that's, so we didn't really get into it, but this is C syntax for specifying, specifying a function pointer. But we've seen how to define pointer types already. We've seen how to define function types, right? That's, there's no difference except for the syntax of how we express that versus our way with Hindley-Millner and with this way here. Okay. So now that you're all 100, well, let's say 80% masters of function parameter passing semantics, what are the semantics of Java? Say I say that. Potter? Pass by value. Pass by value for primitive. So primitive is being in cars, whatever the standard built-ins are. And pass by reference for objects. So is that, is that true? You think so? So what would that mean in Java? When you pass in a object. I'm not talking about how it's implated. Are there any pointers in Java? No. So it doesn't make sense to talk about pointers. All we have are objects. We have variables. We're calling functions. Let's look at an example. So maybe we can debate this, look at this some more. Okay. So here I have a function. So now we switch to Java code, right? So here I have a class called testing, which has a field called foo.  So okay. So we finally get to our main function. So I'm going to create a new object called testing. I'm going to create a new object called snap. I'm going to set an object called bar and an object called snap. I'm going to set bar's foo to be zero. I'm going to set snap's foo to be 10. I'm going to call a function called pass by question mark. That's going to pass in bar and snap. And it's going to print out both of their foo fields. So what is it going to print out? Why do you need to know the function? So by knowing the function, we can know how they're actually changed. So if it was passed by value, would we need to know what the function is? No. If it was passed by reference, would we need to? Yes. Okay. Let's look at this function and pass that question mark. Okay. Here the formal parameters are we have a parameter a of class testing and a parameter b of class testing. So the first thing I'm going to do in this function, I'm going to say b is equal to new testing, create a new object of class testing. Then I'm going to set b's foo to be 100 and I'm going to set a's foo to be 42. So now you can see both functions. So what's the output here going to be? I guess the first question is about Java code. I sure hope so, because like it compiled and ran. So what's the output here? So is it passed by value or passed by reference? 42. That's it. So bar.foo is going to output. And output what? 42. 42. And snap.foo is going to output 10, 100. Is it passed by value or passed by reference? So are these objects?  Is it passed by value or passed by reference? The passed by question mark. Right. So then what is snap.foo going to be after this function is called? It'll be 10, but I'm passing, I'm creating a new, I'm setting b's equal to new testing here. So it's passed by reference. It'll be 100. So what's this program going to output? Is it passed by value or passed by reference? Yeah. It's passed by reference, but the b reference is lost when you finish the question mark. So it'll be the previous 10. What do you mean the b value is going to be? Isn't the so, b value in there testing places it there, but that particular reference is lost. Because of that scope, so this is going to be a deallocation error? The object, taking a new object, wouldn't it be linked into the group as a snap? So would it be linked into snaps rather than the b value? Yeah. So when it is just Java, it isn't directly passed by reference, they call it, you can reassign it, but that doesn't go back to the variable you passed on. If you do reassign it, then the changes don't, the reference doesn't. So what if we, so based on our definitions, is it passed by value or passed by reference? Passed by dereference value. Passed by dereference value. You should write a blog post about that. That's not a bad name. Okay, so have we come to a decision on what the output of this program is at least going to be? 40. 4210? Yeah. Does everybody agree? Anybody disagree? This question, everything you thought you knew about Java has been so long since you programmed a Java, thinking in pointers at C now. Is that good? Hmm? Is it good? You're thinking pointers? Yeah. That's good. You gotta have both. Okay, so, do I run this anywhere? I think so. Okay, so it does run. It definitely does. I've run this. So it all goes back to, what do we say about the semantics of Java's assignment operator? So I believe we called it sharing semantics, where the names on an equal statement, the names get rebound to a new location. Right? So when you say A is equal to a new foo, you bind the name A to some new object foo. And then when you say B is equal to A, you're saying that B is now bound to that box foo, that same new object. Right? So, Java is this weird case where you have kind of both. So, you are gonna get, so bar dot foo is gonna output 100, so it's gonna be, sorry, it's gonna be, what do you say, 4210. Or 42, yeah, 4210. That's what it's gonna output. Right? So Java has this weird, it is, so, can think of it as, let's see, is that right? I don't know that I believe this statement. Okay. So the problem is that we have an object, and we're not copying the whole object into there, right, as we've seen. So we can call methods on an object, we can change fields on that object, and those changes will propagate. All right, so then let's talk about how this is implemented under the hood, and hopefully this will help us think about it. So, what are we talking about with pass by dereference? Yeah, pass by dereference is valid. And it essentially makes a copy of that pointer inside the function. And so, if you re-put another value onto that pointer, it's lost at the end of it, and you don't see where that is. And the only reason that works is that you don't see where that is. So one language is the JVM written in that runs Java programs. C, right? Or maybe C++. I don't know if you're certain, but yeah, you got it. So I guess I think about it. I don't have as much pointer as he does, but the way I think about it is just two levels. So when it's on the first level, then it's pass by value. But when you get to that second level pass by reference, so in this case, when you object in there, that was the top level action that kind of overrode everything else. And that's why I think you're trying to find it. Right, so it's definitely pass by value, because we can't change what we pass in, what that points to. So it's definitely, at least by our semantics, the way we're defining it. So it's definitely not pass by reference, because we're not changing... There's no way we can change what bar and snap are bound to from inside this function call. So definitely not pass by reference, and definitely not pass by name, because that would be crazy. So it's got to be from our definitions pass by value. And so if we don't want to change our definitions, then we can say, well, it's passing by value, and the assignment semantics are such that a.b.foo is now bound to a new location which has the value 100. So the way I think about it is actually by thinking about it under the hood. It's all pointers, so it's passed by value with pointers everywhere, and they just don't ever let you have access to any of the pointers. So that's how I like to think about it. So you can never change something that calls you because you can't get to that raw pointer to change it, because it's passed by value. But you can change fields just like you can change structs, fields of a struct when you pass a pointer to a struct into a function. So the output was 42.10, correct? Yes. I meant to put that on here. Questions on this? So this is kind of showing how murky things can get. We started thinking about different languages and different types of semantics. Okay. So now I want to take some time since we're at this really cool low level talking about code and how it's implemented. So this is something that I really want to do because of my security background because we've been like touching this issue almost, and so I just want to cover this so you can say, yes, I learned about this and I know exactly how this thing works. So some of the implications of, so what's seeddeckle? Yeah, the x86 Linux calling convention. So it's a calling convention for x86 processors of how to call functions. So what's stored on the stack when we call a function? The base pointer? Return what? Return address, which is what? Yeah, the next instruction to be executed when that function returns. So those are both saved on the stack, right?  What memory can you read and write to? A high level. Any allocated memory? Yeah. So pretty much anything. You can at least try. You can try to write or read from any memory. You can definitely read or write to any allocated memory. So what prevents a function or a program from changing those values on the stack? Nothing. Nothing, right? Nothing. There's nothing, there's no protection. It's just, what is it to the compiler, to the processor, it's all just memory. Right? So what would happen if a function did and changed one of those values? Changed. What was it? You would have, what? A suite? Weird way to think about it. Yeah, so if we could so can we write to the stack as a program? How do you know that? Because that's what the program's doing, right? It's pushing values onto the stack. It's writing to that memory. So clearly our program has permissions to read and write to that stack. So what would happen? Where the instruction pointer is? It would probably just terminate, why? Yeah, what is it zero memory? So yeah, when it gets to the return instruction, right? Where it pops a value off the stack sets the instruction pointer to that. Does the processor know that you didn't actually come from zero? No, it just knows, hey, I'm supposed to take that value off the stack and start executing at it. Doesn't. So when I say that you can read and write everywhere your program, so basically the OS tricks your program to think that it has all access to the entire memory. So you can try reading and writing it everywhere. Whether that's been allocated or deallocated, that makes a difference. So that's how virtual memory in the operating system means that your program thinks it has the entire address space. So you don't, so there's actually no way that a program can access the operating system memory because it doesn't, it literally can't even ask for that address because it only sees everything that's all in its process space. Okay, let's look through an example. So this is kind of, we're exploring this question of what would happen if these values change during program execution? Okay. So we have a function very similar to what we looked at before. So if you've kind of already done this I will kind of briefly go over this or I'll go through it a little bit faster than I have before. So please, definitely ask questions. So here we have a function, my copy that takes in a string pointer. It has a local buffer called foo and how many, how much space is there for foo? Four bytes? How do you know four? Because there's a four there. Yeah, because there's a four here, right? This is how we specify. So we're basically saying I want where is, and where is foo stored? On the stack. On the stack, why? It's a local variable. It's a local variable, right? It's not global. So it has to be stored on the stack. Okay, now we're going to string copy string into foo. So what are the semantics of this string copy function? Right, so copy so it's string copy destination source. So take string take a byte, the first byte of string copy it to the first byte of wherever foo points anchor in both of them and keep doing that until string points to its null byte a zero. And you keep doing that and keep copy it. All right, and then just return. So our main function we're going to call calle and we're going to pass it an awesome string about csc340 being the best class you've ever taken and that rocks. Then we're going to printf after, so we're going to just print something else and then we're going to return zero. So is this a valid c-program? Oh, that's right. I changed the name of my copy because I wanted it to be not the same as the last one. So yeah, change this to my copy and then do we have a valid function? Yes. Okay, awesome. Good eye. I'll make a little note. This is what I'm programming on. Powerpoint is a lot easier. Okay, so this code compiles to x86 code that we've seen. So we first have the main function which does pushEVP, move the stack pointer into EVP, subtract 16 bytes from the stack pointer. What is this called in the function? Prolog. The prolog, everything that happens in the function before hit. Then we're moving some value onto the stack pointer and calling my copy. So what is this value? It's the instruction pointer. It's the address. So it's on the stack as the first thing that we pass to my copy. So what are the semantics of passing values onto the stack? So we push from right to left the values onto the stack. But there's only one parameter here. If this is the value on the stack and this is the parameter, what must this value be? A pointer to this string. So the compiler said, oh, there's a constant string here. Let's just put this at some memory location. It just decides there. And then it says, okay, now I'm going to push this address onto the stack because we're passing in a car star. And what's inside of a car star? What's the value? We're going to draw the box circle diagram for a car star. What would the value of it be? An address. An address of some string. Okay. Then we're going to move another value into eax, move eax onto the stack pointer and call printf. So then what must be in this value? Huh? Another string. What is that string? Yeah. After, right? The string after. Okay. So we don't know what these values are, right? But the compiler knows. It created global memory for these. And so it can pass these functions here. We move zero into eax, call leave and call return. What's the zero in eax? The return value. The return value of what? Of main. Okay. Let's look at the myCopy function. So we push evp, move the stack pointer to ESB. We subtract 28 from the stack pointer. We move evp plus 8 into eax. What's evp plus 8? So 8 is up or down on the stack. Up. So let's see what it's doing with eax. So then it moves eax into esp plus 4. It takes evp minus c and puts it into eax. Then it moves eax onto the stack. And then it calls string copy. So maybe let's step through this to kind of see what happens. Then it calls leave and calls return. Okay. So let's, yeah. Which one? Say that. Yes. So it takes evp and adds 8 to it. And then moves, take whatever's in there and move it into eax. And then take whatever's in eax, which is what we just moved, and move it into esp plus 4. So the stack pointer plus 4. And then take what's in, take evp minus c from it and take that value and put it in eax. And then move eax onto the stack pointer and then call string copy. So let's step through this. Okay. So here we have our registers. This time we only need to care about 4 registers. We have a bunch of assembly on the right. And we have a stack that's going to get surprisingly large. Okay. We'll just keep it at a previous value that we already had the stack at. So the stack pointer we know is fd2d4. Because I say it is. And the base pointer is something, but what do we know that the base pointer has to be? Yeah. The location of the frame pointer of the previous frame. So what do we know about it in relation to the stack pointer? It's got to be above it. It's got to be above it, right? So that was the problem we had last time. So I believe this is above it, right? It's higher? Good. Okay. I definitely made that. All right. And so we say that the instruction pointer is fd2d4. Okay. So now we're going to kind of step through this. If you have questions, feel free, raise your hands. You guys know the drill. Okay. So we're going to push evp onto the stack because we want to save whoever called us our callers evp, right? Because we need to use evp as our frame pointer for function making. So we're going to push evp so we're going to move the stack, the current stack pointer into evp setting our base pointer as where the stack pointer is now. Then we're going to subtract 16 bytes from the current stack pointer. That's 10x. So that's going to move the stack pointer down. Then we're going to move this constant value whatever, some crazy constant value onto the stack pointer, which is right here. And then we're going to call myCopy. So when we call myCopy, what happens? It stores the next address. What's the next address? 423. Yeah. So it's going to push the next address to be executed onto the stack. So here we push 8048423 onto the stack and the current stack pointer is pointing at fd2pc. Okay. Everything is pretty normal, right? Yeah. Okay. Now we're going to push evp onto the stack to save main's base pointer. Right? We're going to move the stack pointer into evp. So now we're setting our base pointer right now where the stack pointer is. And then we have to subtract 28x from ESB, which is, I believe, 40 I believe it's 40 in decimal. So that's 10 things I had to make room for. So everything got a little bit smaller. If you have questions speak up. Okay. So we move the stack pointer all the way down. But the base pointer is still pointing at the top where the stack pointer was, right? So we just allocated some local space for our function by moving the stack pointer down. So now it's evp plus 8. So we talk about this. What's evp plus 8? What was it? Yeah. The location to that string that we passed into call e. So we're going to take that. We're going to put it in eax and then we're going to take what's in eax and move it onto the stack plus 4. Okay. Next we're going to take the base pointer evp minus c. So it's evp minus c. So what do we know about references from the base pointer? So we know if they're greater, if they're added then what does that mean? That's definitely what it means. What does it mean semantically? What is that to the function? What was that? Parameters. Yeah, they're parameters to the function. Right? What about negative from the base pointer? Local variables. We're going to address evp minus c. Which local variable? How many local variables does my copy have? One. So foo. Right? So that's the location of foo is at evp minus c. So we're going to take evp we subtract 12 from it or c. We're going to move that into eax and then we're going to move eax onto the stack pointer. Right? And then we're about to call the function string copy. So now what are the values that were what are the parameters that were passing the string copy? Yeah, foo and string str which is the parameter to call the, or to my copy. So here, so, right? And this makes sense, right? So where is foo? What's the address of foo? It's right here. It's fd2ac. Right? We calculated it. It's at evp minus c. And we know the address of the parameter string because that was passed into us. Right? So we know that that comes from up here which is what got passed into us. So now it's what string copy going to do. Yeah, so it's going to say hey, whatever's at 804 8504, if that's not a zero copy whatever that byte is to wherever fd2ac increment both numbers by one. So we move up one more byte and we keep doing that. So copy copy copy copy So when we increment fd2ac, which direction is that going to go? It's going to go up, right? So when we copy that string, we copy increment copy increment copy increment we're going to copy up the string. How many bytes is there between us and how many bytes do we say that foo could hold? Four. So the compiler looks like generously gave us a little extra space and a little extra breathing around the stack. How much space is there between us and let's say something important? 16? Yeah, 1, 2, well it depends on how we count. Yeah, I think it's 3 boxes. So 12 bytes in between us and what's this fd2d0? Was it? The stack. Was it semantic? Where'd it come from? It's what? It's not the return almost. Yeah, it's main spring pointer, exactly. So the first thing that we did was we pushed evp on the stack right here. And that's where this value came from. So then what's above that? The next address the address of the next instruction that we're going to start executing from when we return. Awesome. Okay, so we call string copy So now is our stack look like? Does it look like this? Nope. Alright, we need to know where our string is, right? So this our string, right? There's a 0 at the end but these are just the sequence of bytes. So these values whatever the hex values are, these are represented in the string. String copy takes that so it takes at fd2ac so it copies asuspace those 4 bytes into fd2ac so it looks like asuspace and it's a little weirdness. What's 20 in ASCII? Let me know if it's up ahead. Space. So why is it 20, 75, 73, 61? What's 61? Hey little endian. Yeah, so architecture, endianness of integers, right? Which is the least significant byte and the most significant byte?  When you look at that and you look at it as an integer, this is what it looks like. The integer of whatever hex 20, 75, 73, 61. But does the copy function stop after copying these 4 characters? No. When does it stop? What end? The string terminates and which string? The value that is passed The value that is passed is the second parameter so in this case 804, 8504 right, this string so it's going to keep copying until the end here So the next 4 bytes are going to be cse space and is it done? No. No, it's going to do 340 space Is it done yet? No. Oh, it's going to do fall and then it's going to do space 201 and then it's going to do 5 space RO and then it's going to do cks exclamation point and then it's going to write out a 0 right after this but I didn't want to it didn't line up perfectly so I didn't want to include it So what happened to our stack? Clobbered So is my program going to stop? No. No, right? It's returned string copy said hey I did what you wanted me to do I took one string I copied it into the location you gave me and now it's returned to you All right, leave It's a reverse of this so it's going to set the stack pointer to the current base pointer and popEVP So what's the value that's going to be in EVP? This one here? So if you do popEVP here I'm just going to take whatever that value is copy it, put it in EVP because that's all that these functions know how to do. They just take the value off the stack and put it in there Okay, now like return so this mandates up return Take that value that's currently on the stack put it in the instruction pointer and start executing there right? So can I start executing at<PHONE_NUMBER>? Probably not because there's probably no code there, right? So what am I going to get? Segmentation fault Segmentation fault, right? Because I tried to access memory that has not been allocated to my program so that's going to give me a segmentation fault So and you can run this, you can test this in GCC, you can run you can run it it'll give you a segment fault if you put it in GDB to debug it you can run it and it'll say, hey I'm starting this program everything's awesome and then it goes, oh no I got a segment fault here because I tried to execute this memory I tried to I tried to access this memory location that doesn't exist to try to execute stuff and if you look at the registers here you can see that the EVP, we changed the value of EVP because we erased the save base pointer and we changed the stack pointer the instruction pointer to be whatever we wanted Okay, so so why is this a problem? Why is this a security problem? Because you can access memory that you aren't supposed to be able to access You can access, so yeah I could get your program to crash Do I really care about crashing your program? No Maybe, it depends on what it is, right? If it's going to give me a million dollars if I crash it then I want to crash it Yeah, so what if I so I can control the instruction pointer that means I can control where your program goes to start executing so if I can get it to start executing something I want then it'll start interpreting my data that I gave your program as code and start executing my code which means I'm running an editorial process and I can do anything your process can do So this is one of the most common vulnerabilities in C and C++ So I really want to show this to you guys since we already talked about the base pointer and the EIT because it's really cool and very important Anyways, thanks for listening See you guys on Monday, Wednesday