Download and watch the episode here:
Coding 101 6
Shannon Morse: Today on Coding 101: Let’s play some games; let’s play some music plus discussing object oriented programming and function return.
Netcasts you love, from people you trust. This is TWIT! Bandwidth for coding 101 is provided by CacheFly at cachefly.com.
Fr. Robert Ballecer: Welcome to Coding 101, it’s the TWIT show that gives you the knowledge to live in the wonderful world of the code monkey. I’m Father Robert Ballecer.
Shannon: I’m Shannon Morse and for the next 30 minutes or so we are going to get you coded up on all the code that you ever need to know.
Fr. Robert: That’s right. We’ve been talking a little bit about functions this past week and I know it’s been causing a little bit of angst in our community.
Shannon: It’s a little confusing.
Fr. Robert: It is a little confusing and it’s a high level topic and so we thought it would maybe be a good time for us to do a quick rewind and bring you up to speed on what we expect coming into this lesson.
Shannon: Exactly. So why don’t we go ahead and hit it off with doing a really quick review of Lou’s code from last week and I’ll also show you what I came up with as well because I came up with some pretty cool stuff.
Fr. Robert: I heard.
Shannon: So let’s take a look at my computer and I will show you Lou’s code from last week and just give you a general overview of what he did. He has a nice little while loop here and then he goes into this function. Up here he’s basically saying if you click A; and I’ll go into why that number 65 is there; or if you click B you’re going to choose this one. Click C selection number 67 and then if you click Q, escape or enter you’re going to hit 27.
Fr. Robert: Now a quick note about this because this was actually brought up in our Google plus community. People were wondering where did he get the numbers from. Please just jump onto Bing, jump onto Google and look for C sharp and key press assignments. We’ll actually give you what numbers are associated with which keys.
Shannon: I actually did find the table for that over at the Google plus community somebody linked over to that. I’ll show you in just a few minutes where you can actually find that. Going on with Lou’s code – he also included a whole bunch of – generally a menu that you can choose from. Request word, convert to binary or just say hello and then q to quit. Each of these just goes into basically a stream. The first one is: what word do you want to repeat? Do you want to repeat monkeys? How many times do you want to repeat monkeys? Say 9 times and then it prints it out 9 times for you. The 2nd one he did was converting an integer to a binary. You enter a whole number that you want to include and then it goes into converting that integer into a binary down here. So it changes that right there. As we scroll down we see the 3rd option which is just saying hello. So it takes your name and says Hello to you. Let’s go ahead and hit start. I’ll click on start and run it. So it just gives me the menu. I’ll say let’s choose A. Which word do you want to repeat? Monkey, how many times; 7 times. B is converting to a binary so I’m going to convert. Let’s do 56. It converts that – a whole bunch of zero’s. Wow! That is a lot of zero’s. Then C is just saying Hi Shannon and I’ll hit Q to quit. So it’s very, very, simple and it basically took everything that we’ve learned up to this point and included all of those as different menu options. With my example I decided to make a little game out of it. I’m going to go up here to open projects and I’m going to choose my project – my Snubs example. Let’s choose episodes 6, Snubs example. Ok so if you take a look at this one it kind of starts off the same way as Lou’s example. I have this while loop up here; if you choose A number 65; if you choose this one it says magic. That’s the name of that function.
Fr. Robert: Right, so you’re just calling the function called runaway and a function called magic and a function called sword.
Shannon: Exactly and then Q to quit. Down here we have a whole bunch of different write lines for the menu. Runaway, use a magic spell to stun him; stick em with the pointy end of my sword – because I watch way too much “game of thrones”. Then we have all of the different string options. The first one is the dragon chases you and fries you to a crisp. Maybe I shouldn’t give all of these away. Let’s play the game shall we? Do you want to play a game? You walk into a forest looking for trouble. What do you do when you run into a dragon? I’ll say I’m going to do A, I’m going to run away. In red it tells you that the dragon chases you and fries you to a crisp. Game over. Let’s try again. This time I’ll choose stick em with the pointy end of my sword. You used the sword on the dragon’s weak point and destroy the beast. Congrats, you won! Do you want to play again?
Fr. Robert: Yes I do.
Shannon: Ok, let’s choose B this time. I’m going to use a magic spell to stun him. What kind of magic spell do you use?
Fr. Robert: Avada kedavra?
Shannon: Your magic ability Avada Kedavra destroys the dragon instantly. You won! Yay!
Fr. Robert: I love this. This may be a little too - for you but I grew up with mutts – the dungeon adventures.
Shannon: Me too.
Fr. Robert: Text based and I love it. Now you did a very simple one.
Shannon: Yes very simple. I could do much, much, more advanced and if you choose magic then you get a whole bunch of other options so what kind of magic would you prefer? Fire, water or air; then if you choose air something else happens or you run away and fly off into the wilderness. I could definitely go much deeper with it but I choose to keep it very simple for time and I had that much time.
Fr. Robert: You get to the end of the program and say I’m kind of dumb with this but what I like about this is that your code demonstrates a few things that are very important about functions and that is that you want to be able to call these things whenever. If you were doing a full blown text adventure then you don’t want to have to put a bunch of “if else” statements always at every point, spelling out every possible situation and every possible outcome. This way you can say here is outcome 1, outcome 2 and outcome 1000 and it just calls it when they need it. I love that, that’s really, really, good.
Shannon: Super fun. Now we were speaking about the different character codes that you can use in visual basic for Windows. I found the whole table of all the different keys that you can use and what their values are. You have all sorts of different ones and descriptions on this link. This is over at msdn.microsoft.com. We’ll put this link in the show notes for everybody that needs to use this but this’ll give you a general overview of all the different ones and a nice little description of each one. Also I did want to mention whenever you do use this it doesn’t matter if you use lowercase or uppercase because either way your output is going to be the same.
Fr. Robert: I love this part of the show now. Any time we get to see what people have done with some of the code that they’ve gotten from the show – please more of that.
Shannon: I totally agree. We got quite a few on Google plus. I’m just going to pull these up real quick and of course you can find our Google plus community over at gplus.to/twitcoding101. The first one comes from Benjamin, he sent in 3 different ones and he just sent us the code so I went ahead and compiled each one. This first one is very simple. It’s basically just asking you to type in a 3 letter airport code and then it gives you the actual name of the airport. He only has a few available for this example so I’ll type in FRA and it’s Frankfurt. Would you like to go on? You can choose yes or no. So I’ll choose no and it closes it – very simple.
Fr. Robert: Basic program, you come in and it asks you what data you need to interpret it and it gives you the output and then it asks you if you want to quit.
Shannon: It’s great, very simple, I liked it a lot. The 2nd one asks how many numbers you want to sort. So I’ll say I’m going to sort 6 of them. Number 1 is going to be 3. Number 2 is going to be 6544. Number 3 is going to be 76. Number 4 is going to be 65. Number 5 will be 12. Number 6 will be 9. So it takes those numbers and sorts them from low to high.
Fr. Robert: That’s actually way more useful than it might look because that’s a basic sort function. It uses a series of conditions to tell whether or not is this number higher, is this number lower, where should it go in the order? That’s a piece of program that you will use time and time again.
Shannon: It’s a very simple script as you could tell when I was scrolling through it as well. Very easy to write and I really enjoyed that one. Now his 3rd one was awesome. I love this one. Let me just turn up my speakers real quick. So if we take a look at this he called it stopwatch and if I scroll down you see it says Super Mario right here. That’s kind of weird. Duration of the song and then over here we have a whole bunch of beeps. Strange right, but let’s click start.
Fr. Robert: Now if you haven’t noticed that is Super Mario’s theme song entirely in console beeps.
Shannon: That’s so cool!
Fr. Robert: Now I will say and I said this in the pre-show; when I was teaching this would be the first thing I would tell my students they can’t do. I didn’t want console beeping just because they would always over use it.
Shannon: It gets annoying.
Fr. Robert: It is annoying but it is fun now!
Shannon: It tells you the duration of the song lasts 26.98 which he had written that into the code as we saw. So cool; I had no clue that you could use C sharp to make things come out of your speakers.
Fr. Robert: Oh absolutely.
Shannon: It makes sense.
Fr. Robert: Now the console command was one of the very first that we covered. In fact it was the first command that we ever covered on the show. It is incredibly powerful. If you’re in the ID, if you’re playing around with that integrated developer environment go ahead and type console dot and it will give you a menu of all the different things that that console can do. The wonderful thing about that is that you can experiment. Go ahead and play around with some of the different options, some of the different features and functions of the console and see if you can maybe make it do something you were not expecting.
Shannon: I love it. That is so cool and so much fun. Alright, I have to share square iguanas.
Fr. Robert: Iguana obviously you are not just a novice at this but your stuff is awesome. So yes, let’s take a look.
Shannon: It’s so cool. This is his episode 3 example and he said he couldn’t find anything really interesting to do with just 4 loops that he didn’t already do in his last example. Here’s a text to Morse code translator. Now if you actually use the github code that he includes with this comment; he says if you comment out or basically comment in the information you can actually hear the Morse code come out your speakers. So we have 2 examples about using your speakers with your console commands.
Fr. Robert: Square Iguana you are awesome.
Shannon: He showed a couple of others. I’ll just run through these real quick. Episode 4 example basically takes this – I was originally going to move a character around but creating the code led me to bug in my code. That was interesting. The character left a trail behind him so I thought this was something that I could do a little bit different. This is how the paint application got started. This basically tells your mouse movements to create a little painted snake on your computer screen. Isn’t that cute?
Fr. Robert: This could very easily be turned into that snake game that everyone had on their phones back in the 90’s and 2000’s. It looks like a simple piece of code but honestly you could take simple pieces of code and modify them to do incredible things. Again that’s what we’re all about.
Shannon: I love it. Of course his 3rd one is from last week’s episode and this was the menu. We did our own menus. He created a really nice menu version, more of a gooey option where you can select with your keyboard or your mouse, not a series of commands. He decided to make a real menu. He didn’t have the time or energy to create something more complete but he did create a page for each menu item even if just a simple message. Very, very, cool. Thank you Square Iguana.
Fr. Robert: Great examples and again please make sure you give us your examples. Either put them into the Google plus page with the output or give us your code. You know what? If you give us your code we’ll add it to the Coding 101 git so people can play with it. This is one of the things that I do all the time. I don’t know about you Shannon…
Shannon: I’m starting to. I’m getting really excited about it.
Fr. Robert: You take code that works and you go oh that’s great. I wonder what happens if I do this. Let’s add another loop, let’s put another console command. That’s how you learn.
Shannon: So how about we move on.
Fr. Robert: Yes I think so. Now we’re going to move on by moving back.
Shannon: I think we should do a little bit more review about functions because I was a little bit confused last week.
Fr. Robert: People kind of freaked out and it’s ok to freak out. It’s because functions are so important and no matter what language you are using it begs a little extra time. Before we get to functions I want to talk a little bit about something else that a lot of people were demanding we talk about in episode 1 and it just didn’t make sense. Now it does. That is object oriented programming. Have you heard about this Snubs?
Shannon: I think so. I heard some people mention it in the Google Plus community. But I’m still curious what makes object oriented programming different from any other programming.
Fr. Robert: Right. The programming that you may be used to - let’s say you started with basic – let’s go way, way, back. That is more structured program. In structured programming the data is separate from the code so what you do is write the code and then you run the data through the code and you get output.
Shannon: Oh ok.
Fr. Robert: It works. Structured program is actually very simple to pick up because in writing the instructions it’s easy for me to picture what it’s going to do, but it’s not all that flexible and one of the other things about structured code is it gets us back into that nightmare of having to rewrite the same section of code over and over again because you’re going straight down.
Shannon: I don’t understand why anybody would want to do that when you have the option to do it this way.
Fr. Robert: Right. The differentiation between structured and object oriented programming is actually not that big. As you get into the more modern languages even the ones that aren’t technically object oriented have a lot of object oriented language concepts in them. The basic concept is this; rather than having my code and then having my data I write it so that my code and my data are integrated into what’s called an object – object oriented programming.
Fr. Robert: Let me give you an example. Let’s say I’m writing something for traffic management. In structured programming I would write this crazy long piece of code that could account for all the different variables that might possibly run through a traffic system and then I would run date through it to see what kind of output I got. Easy if it’s a short program but if it’s long forget that.
Shannon: It would get confusing.
Fr. Robert: It would get incredibly confusing. In an object oriented programming language what I would do is break it down just like we were talking about from episode 1; breaking things down into their component parts, into the puzzles that could be solved easily by computer. So rather than saying I’ve got 1 long program that runs the traffic lights I say I have 1 object that turns lights green. I have 1 object that turns lights red. I have 1 object that looks at cameras to see how traffic is moving. That’s the world of object oriented programming. It looks at code and data as 1 thing. Rather than separating it, it, says here is a chunk of the world, I pull it out and this is how I’m going to deal with it.
Shannon: Oh wow, ok that makes sense.
Fr. Robert: Easiest way I can explain it. That’s why even languages that aren’t technically object oriented languages – they have a lot of object oriented components because if you’re breaking down the puzzle into those pieces the computer can understand you’re essentially treating it like an object oriented language.
Fr. Robert: Does that make sense?
Shannon: It makes sense.
Fr. Robert: Good. Alright now let’s break this down a little bit. What I’d like to do is if you could go ahead and bring up our github and bring up episode 5 code; we’re going to look at some of the topics that we touched on last week in order to do a revamp of functions. Now going to the blackboard – this is the exact same blackboard from last week. We know that the basic structure of a function is this: visibility, return type, name, and parameter. Now again, to explain that; visibility is just whether or not the function can be seen by whatever. You can set it public, you can set it private, and there are a couple of other visibility parts. Don’t get confused by that because the main action is going to happen after. That is this; return type, the name and the parameter. These are probably the most important things you’ll deal with right now before you get into super crazy complicated program. The reason for that is the return type is something we’re going to be playing with today. We’ve been using functions just to execute static code.
Fr. Robert: We’ve been using them like procedures. In other words when I call the function go do something; but that’s not the most cool thing that a function can do. What a function can do is actually return something to us. So we could give it some data, it could work on that data and then return an answer to us.
Shannon: Oh that’s cool, so we could make it do math or we could make it relay a really broad example with just typing a few keys.
Fr. Robert: Or we could say return a string - something that we wanted to print. Basically anything that is a variable. Anything that you’ve played with already when we talked about variables you can make a function return. The way that we do that is this; we have to tell the compiler what kind of data it is going to be returning back. Is it going to give me an integer? Is it going to give me a string? Is it going to give me a floating point? All of those different types work here. Now the name is just like a variable. It’s just the name of the function.
Shannon: You can name it whatever you want.
Fr. Robert: I can name it anything I want. Just remember that because it’s object oriented programming and because it’s a function we like to call functions that are descriptive. I don’t want to call this function x because function x could mean anything. I want to say light turn red.
Shannon: A good example was when I did my little game on here, my little text based adventure game. I named my different functions sword, magic and run away. It was descriptive enough that I knew exactly what it was going to call back.
Fr. Robert: The reason why we do that and we’ve talked about this before is if you said function 1, 2 function 3, you would understand that because you’re sitting in front of your screen for 2 hours and you’re getting your code.
Shannon: But if somebody else had to come in and look at your code they would just be like what does this mean and then they would have to google function 1 or try to figure out what it was.
Fr. Robert: That illustrates 3 of the things that makes object oriented programming better. The first is that it’s easier to understand because if you’ve got functions that are called by what they do it’s easier for someone else to pick up or even for you to pick up 6 months down the road and say oh yeah I know what it does because the function is named. Also it’s easier to maintain. In other words if I need to fix it, if I have to go back in the code I don’t have to remember that it was function 5532 that did this. I look for there’s something wrong with the menu – let’s go to the menu function. It’s also easier to upgrade because I’ve encapsulated everything within those functions it’s easy to pull that function out and put some place else or replace it with a better version.
Shannon: Oh that’s so true. I didn’t even think about that. You’re right.
Fr. Robert: That is again one of those things that we like about object oriented programming. Now let’s go back to this. So we know that we’ve got our function declared. Visibility, return type – let’s say it’s an integer so it’s going to return me a whole number. The name is going to be answer. Again that’s not a great name, I would never use that in an actual program but we’re going to do it here because the chalkboard is small. Then the parameter is the data that’s going to go into the call. Remember what I in object oriented programming where we treat the data and the code as one object?
Fr. Robert: In order for me to have that I have to have my code and I have to have my data. My parameter gives me the data.
Shannon: Ah ok.
Fr. Robert: Now here was the example that we had. We had public so it’s a public function; int – so it’s going to return an integer; answer – that’s the name of the function and then int a and int b. So I know that it can receive 2 whole numbers. Then my code when I run it says int c equals a plus b. So C is going to become the sum of anything I pass into the function.
Fr. Robert: So if integer A comes in and it’s worth 3 and integer B comes in and it’s worth 2, integer C is going to be worth A plus B which is 5. Now here’s the trick – return. We didn’t use this in any of the functions from last week. Return C. So what I’m now saying at the bottom of the function is take the value of C and return it. Return it as answer. So whatever piece of code called the function – I set the answer as x, y and x was worth 3 and y was worth 2. When I call it this is going to come back and replace answer with 5.
Shannon: I totally get it now.
Fr. Robert: That’s all it is. That’s what a function is when we’re using the return.
Shannon: That’s so cool. Alright so we have a public integer named answer, it’s going to look at both of those integers, A and B – whatever that input ends up being and then it runs the code that says integer C is going to equal those 2 inputted numbers A and B and it’s going to return to you that answer which is C.
Fr. Robert: Right. I want to extend an olive branch to the more experienced code monkeys because there are a lot of people out there who really got upset and were like wait a minute C sharp doesn’t have functions. That is technically true because C sharp doesn’t have any standalone functions. Every function inside of C sharp is attached to a class which is another program that we’re not going to talk about right now. Which technically makes it a method but it works exactly the same and the reason why we’re calling it a function is because function is the universal term. That works across all programming languages. So if you are brand new at coding and someone comes up to you and says you do realize that you’re not actually making functions, you’re making methods – just smile and say yes I know and continue writing your function. Don’t get confused by the terminology.
Shannon: I see why you’re calling it a function then. Just so I don’t get confused.
Fr. Robert: Yes because we’re going to be talking about a lot of different programming languages on Coding 101 and function is the universal term. It might be called a procedure, it might be called a method but it works. If it works like a function, if you code it like a function, if it returns a value like a function it’s a function.
Shannon: Alright, got it.
Fr. Robert: Isn’t this normally the time of the show where we invite someone like a code warrior to come on?
Shannon: I think it is.
Fr. Robert: You know what I hear? I hear Lou.
Shannon: Do you hear the call?
Fr. Robert: Actually I hear the beat. Lou where are you?
Lou Maresca: Hey guys! I’m in San Diego this week. It’s actually raining here so I brought the rain with me.
Fr. Robert: Welcome Mr. Lou Maresca. He is our code warrior. He’s an employee of Microsoft, he’s been coding for them for an awful long time. Also a regular here on the Twit TV network. You’ve seen him on This Week in Enterprise Tech, you’ve seen him on Padre’s corner, you’ve seen him on Tech news tonight and yes you’ve seen him on Coding 101. Now Lou we wanted to go back into functions because I have to admit, I don’t know about you but I got a little bit of panic. Some people were panicking.
Shannon: Well yeah, when I started writing my own code I was like what am I doing?
Fr. Robert: We’re hoping maybe you can show us some of the nuances of function specifically with the return thing.
Lou: The first thing I wanted to show is a basic function that returns some type of variable. In this case it’s going to be an integer which is a number of some type. What we’re going to do is we’re going to have this function specifically take a couple of numbers. We’ll have 1 be how far we’re going to go in miles and how many minutes we have left to get there. So what this function does is it’s going to return a number and it’ll tell you basically what speed you have to go in order to get there in time. If we notice the functions or what we call the functions schema is it takes a number decimal which this is in miles and again another decimal which has a decimal point in it and how many minutes you’ve got left. Those are the 2 variables it takes. Then it has this return type over here. Normally we showed most of our functions had a void which basically said that it returned nothing. In this case we’re going to be returning an integer. The reason why it says it’s static – it just means that the functions always there available for everybody. I’m sure we’ll get into that more later on once you get into object oriented programming. For right now just know that that means that it’s there for everybody to use. The int just basically means it’s the number returning. So in here real quick I set a variable saying basically this is my return variable. If you noticed down here I have a return statement saying this is the number I’m returning. If I actually remove this return statement you'll notice that it gets angry at me. It says not all code paths return a value.
Fr. Robert: You tell it that the function is going to be returning something and then within the code there’s nothing that returns a value.
Lou: That’s right. The ID’s kind of getting angry with me and saying what’s going on, you didn’t return anything. I’m going to put this back and that should go away. Now I’m actually returning the variable that I created up here. I can get rid of all this code if I really wanted to. If I comment this all out it’d just be returning return required speed and that would meet the requirements of that function because it’s returning a number which would be zero. So in this case I’m going to do a calculation – amount of hours based off of minutes and then I’m going to calculate the speed by rounding down the number of miles – distance is miles divided by how many hours and that should get me miles per hour. Then that will return back. If I go back up to how I’m calling this function – again this is just some console stuff but it just says how many minutes until your appointment and again the way I’m calling the function is by – if you go down here once I get minutes left and the distance in miles from the console – it’s the same console stuff that we’ve done before. I then call the function. You’ll notice I’m passing in the distance in miles and the minutes left into that function. Then you notice this little equal guy over here; that’s basically saying the return type for that number that I’m returning – save it in this other variable called speed in miles per hour.
Fr. Robert: Right.
Lou: Once we have that we’re just going to display that to the user and say ok that’s how fast you actually have to go in order to get there in time and then I also have another function…
Fr. Robert: Lou let’s step back just a second starting at integer, speed and mph. This is an interesting line here because he’s declaring a variable – an integer called speed and mph and it’s equal to – then he calls the function. He’s calling the function called required speed mph and he’s passing it to numbers as parameters. Distance in miles and minutes left. So again this is one of those things that…
Shannon: That’s just like what you had on the board.
Fr. Robert: Exactly what we had on the board but he’s doing it all in one line. I’m sorry Lou, go ahead.
Lou: No problem. So once we pass it does its own magic that’s underneath the hood here and it returns the number back. All we do right now is we basically display to the user and say hey this is the speed you have to go in order to get there in time. Then we also have a little function for people who are using metric. We have one that converts miles per hour to kilometers per hour. That basically is another function. A very simple function, all its doing is taking the speed which is a number in miles per hour and again it’s doing a little math on it, converting that to kilometers per hour. Then it’s returning it. We said we were going to return an integer number type. Now we need to return that so we’re basically returning the number. Then again back up here we store that in another variable so we do the equal sign, say the variable equals the return of that function and then we write that to the console. We run this and it basically says how many minutes. I have 30 minutes to get there and I have about 45 miles to go and it’s basically saying you need to go 90 miles per hour to get there. That’s pretty much it and the nice thing about it is that I don’t have to put all this special code with in line here so it gets a little cluttered here over time. So that’s kind of what functions are all about.
Fr. Robert: Right.
Lou: They’re about reducing the size of your program and making little functional pieces – things that make sense into small chunks.
Shannon: They’re keeping your code clean so that if anybody else has to look at your code they will understand what’s going on.
Lou: That’s right.
Fr. Robert: Now people who are getting a bit more advanced in code, what they’re going to find is if they’re doing it right the actual main section of the code – the main function is going to be really short. There shouldn’t be a whole lot there. It should be calling other functions that are actually doing all the work. What you see in Lou’s example which I love, he’s got functions that are calling other functions. That’s what we want to do because then it leverages all the code that you’ve written before rather than writing something 15, 16, 17 a hundred thousand times. You write it once and then you call it as many times as you need it.
Shannon: I do have a question for you Lou. Since you were pulling 2 decimals and then the integer was the one that got outputted, can you still have a decimal come out instead of a full number?
Lou: You could do that. The reason why I had a full number was just so that it was rounded up. Nobody knows – well I guess people do know how to go 10 and a half miles but…
Shannon: Oh I totally know how to do that.
Lou: Go faster you know. In this sense you could basically, if I really wanted to I could change this to a decimal, again change this to a decimal and I don’t even have to convert this then to an integer or round it in that case. I could just leave the math here to basically say divide by that and now that’s it and I can return the decimal up here. So it makes the code a little simpler.
Shannon: That’s the first time we’ve seen decimals on the show.
Fr. Robert: Lou I’ve got to ask this. Someone who is looking at your code afterwards – because we’re going to make your code available on the github, just go into the show notes and you’ll be able to pull up everything, actually all the examples from today’s show. But someone who’s looking at it and we’re going to ask them to play with it because that’s what we always do right. Get the code; play with a couple of things. What would be the thing that you think they need to play with the most? What’s the thing that they should break; the thing that they should try to rename? What’s the thing that they should try to practice so that their proficiency with functions will grow?
Lou: I think the best thing to do is to just try things out. Basically just go in and remove some things. Let the IDE kind of tell you what’s going wrong. Then try yourself at actually doing some calculations and adding some more functionality in there. Then you’ll maybe even add some additional functions. In my case I returned kilometers per hour, maybe go in and ask the user for kilometers per hour and convert it to miles per hour. Maybe create your own function to do that. Add some more functionality to the application. Try it out and see how those functions work for you.
Fr. Robert: I love this, I remember this when I was still working code; he said one old school rule of thumb in general was that a function should stay within one screen load. You shouldn’t have to scroll up or down. I was always told if it needs to go more it means you need to break out functions.
Shannon: I guess we’re lucky that our resolutions are getting better.
Fr. Robert: I get asked Lou – I mean obviously programming is a lot more complicated now than when I was still coding. Is that something that you still try to do? The reason for it was because if you could have it all in one screen it means that it was simple enough for someone to take an at a glance look and say I know exactly what that function does.
Lou: It’s a good rule to follow. The only problem is that over time the more functions you have – sometimes you do want to have the same function do a bunch of things and that’s only because you don’t want to have to piece everything out into little smaller things that you won’t ever use again. When we get into object oriented program we’ll talk a lot about private things versus public things and a lot of private functionality can sometimes get really complex because people try and break it out into lots of tiny small things. I think it is a good rule to follow that if you have this much code to fit on the screen it makes sense to have that much functionality within there. As you go on you can add more functions and so on. But you don’t want to get too crazy with it.
Fr. Robert: Let’s hear a code confession Lou, what’s the longest function you’ve ever written for Microsoft?
Lou: I’d say it was about 400 lines, maybe 450 lines. That’s pretty long.
Fr. Robert: Again you’re right; it is a good rule of thumb as T Joe mentions in the chat room. It is a good rule of thumb to try and break it down but you get to the point at which if you know you’re never going to use that piece of code for anything ever again and you’re only bussing it out into its own function in order to meet that rule of thumbs – that’s when you break the rules of thumbs.
Fr. Robert: Lou, thank you so very much. Hopefully this is now easier for people to understand and they’re going to go forth and…
Shannon: It’s easier for me.
Fr. Robert: That’s what we want. Let’s get the folks excited here. We had a little chit chat here and next week we want to start getting into some graphics and animation.
Lou: Maybe some Windows form program.
Fr. Robert: Yes, so we’re going to be stepping out of the console a little bit and Lou’s going to show us some interesting doo dads with what else you can do with C sharp. But until then Lou, thank you so very much for joining us. You want to tell the folks at home where they can find you?
Lou: LouMM at Twitter and then of course next week I’ll be in Atlanta for convergence 2014 so if you guys are in the area come out and check out my session there.
Fr. Robert: Everyone should say hi to LouMM he really is a nice guy.
Shannon: We’ll come out there just to say hi to you.
Lou: Alright that sounds good.
Fr. Robert: Now until then we’ve got a couple of tools to help people who may be still freaking out about functions. Shannon you want to tell them all about our show notes?
Shannon: Absolutely. We are over at twit.tv/code. That’s where you can find all of our show notes and a link to our github which is where we post all of the code from Lou as well as myself.
Fr. Robert: That’s right and don’t forget to subscribe to us on iTunes. If you’re an iCoder we want you to spread the word about Coding 101 wide and far. You can help us tell the world about the rise of the code monkey. Go ahead and jump into iTunes and make sure to subscribe to help us stay up on that leaderboard.
Shannon: Of course if you’re not on iTunes you can also find us on Youtube at youtube.com/twitcoding101.
Fr. Robert: Please do. Also we’ve started a Google plus community. It’s still fledging. It’s still about 500 users or so but we’re hoping to get it much more active and much larger. The nice thing about this is we’ve got people in this community who’ve been coding for years and years and they can help you if you get stuck. If you get frustrated and are like, I don’t know what to do with this stuff, jump into that community and they’ll help you out. Just go to, what is it?
Shannon: plus.google.com and go to coding101. And I mentioned Joe in there actually asked me in episode 4 when I saw a bunch of windows pop up beneath my code and said, what is that? It turns out it’s a debugger running in the background.
Fr. Robert: So many of the questions that you might have can be answered by those guys at just a moment’s notice. Also if you don’t like jumping into Google plus why not catch up with us on our other social network. You can find me on twitter.com/padresj. That’s @padresj.
Shannon: I’m @Snubs – super easy.
Fr. Robert: Also did you know that we do this show live?
Shannon: We do?
Fr. Robert: Yes, we’re actually here. Weird, right?
Fr. Robert: Every Thursday at 1:30 PM pacific time you can find us at live.twit.tv slash Snubs is hiding under the table. Also as long as you’re going to watch us live why not join us in the chat room at irc.twit.tv. There you’ll be able to talk to some of the very same people who make our Gplus community so awesome.
Shannon: It’s true.
Fr. Robert: Until next time, I’m Father Robert Ballecer.
Shannon: I’m Shannon Morse. End of line!