 Welcome everyone to how do I learn to code with Tokyo ed tech? That is me today. I'm going to be talking about the topic of coding and learning coding I'm a middle school high school coding teacher and I want to share kind of the order that I teach Coding in and the reason I'm doing this video is one of my channel members Paul kind of asked me, you know, well, what should I learn? What what do I actually do to learn to be a good coder? Of course the answer to becoming good at anything is practice practice and practice But especially if you're learning coding on your own, you don't know what you don't know And so this is the order that I teach this subject in again I teach middle school high school computer programming mostly Python, but I also do AP Java So what I'm going to talk about today is applicable to any programming language But the examples I'll be using will be in Python And as I mentioned Paul suggested this I also want to give a shout out to him Kevin and yawn my other 16-bit members of my YouTube channel if you feel like joining and supporting click the join button down below Let's get started. I'm gonna be talking about the following topics And this is roughly the order that I teach it in so we start out with variables and data types Then we go to input and output getting information into the computer and information out of the computer Control structures, which I'll talk about a little bit later functions, which organizes our code Data structures, which organizes our data and classes and objects, which organizes code data and functions into one beautiful package and then I talk about the different ways of You know interacting with the computer so we have the terminal we have kind of graphics graphical based Programs like games and then we also have GUI based things with buttons and widgets and things like that And then finally we talk about algorithms and complexity so I'm gonna go through each one of these today and just kind of give you a brief overview of what they are and Just a little bit of information about maybe why you know, I do it in this particular order as I said over here I've got some code examples Written in Python, so let's go ahead and take a look at the first thing So we always start out with variables and data types. So a computer essentially stores information so This information has different types So for example, we have as you can see here integers floats strings and booleans in Python now if we're in Java strings would not be a primitive type They're the primitive type there is a care and strings are made up of characters But for Python its integers floats strings and booleans There may be a few others But these are the ones that I start with and I think you know for beginners This is a good list because it covers most of what you're going to need. So you can see here We have some variables. So the answer is 42 Gigawatts is 1.21 Name is Prince. Yes, I was a bit on an 80s theme here and is sleepy is true So we have integers floats Strings and booleans booleans only have two values now if you don't know what I'm talking about right now It's might be good for you to go take a look at my introduction to programming using Python video It kind of answers all these things in detail So I'm gonna go ahead and run this and for those of you that are gonna ask I'm using the genie editor G E A and why you can get it genie.org I think there's a though should be a link down below and it is a free open source editor that works on Linux Mac and of course windows, so I'm gonna go ahead and run this And you'll see here where we've got variables and data types. I've printed that out I've defined some variables and then I've printed them So the simplest form of output is the print statement So you can see here I've got prints the answer to life the universe and everything is I got a little cutoff there Is the answer which is 42 if you're not familiar with hitchhiker's guide to the galaxy Stop watching this video right now go download it buy it a bookstore. Whatever you need you got to read this book And then the first way we learn to get input from the computer so getting information into the computer from human being is the input statement and Something that my students have released most students have trouble with at the very beginning is they have to understand that This variable is going to be a string. So even if I typed 12 in here guess is still going to be represented in the computer's memory by String by the letters one and two or the characters one and two not the value of 12 excuse me a little dry air here in the winter and So you can see here I've got this input statement says please guess my favorite color and I'm going to go ahead and Type green because that is my favorite color and hit enter and then you see here it printed you guessed green So the basic input and output you see over here. We have input Keyboard and mouse. So this is the the main things and they're the easiest actually to Program, of course, there are other things like webcams. There are microphones But they're a bit more complex to use I don't really teach them in in my introductory courses and then the output as you see here is the screen So in this case we're printing and then later, of course, we'll add different graphical things using some graphical libraries And then you can also use the speaker. So we can play sounds and things like that So we hit enter here and show you well, actually, let's go on to the next one So the next thing I teach once the students understand how to get input how to print things to the screen We talk about the different control structures in programming languages. So We've got conditionals. This is the first one that I teach and this is code branching based on a condition So over here, I Asked for what is my favorite color and your guess was and we typed in green So you can see here. I have this if statement So if the guess equals green print. Yes, that is correct If the guess equals black print close because black is probably my second favorite color So that's that's kind of what I tell my students at least and then if it's not one of those two You've got it wrong again. This isn't a coding tutorial. So I'm not going to explain how this works But this is if you don't know how it works, you need to learn this and again, I what I see with Students on Reddit, I see it all the time my channel is they're trying to use things that they're not ready for They don't want to learn things systematically and they have a lot of problems They start to use these libraries and modules They just don't understand without having a strong foundation. So with my students that I teach personally I think it's very very important to work on the foundation Before we start using all of the cool little especially in Python all the cool little shortcuts that the language lets you do So I'm trying to teach from the bottom up so the students have a strong foundation so When I talk about conditionals just kind of a little graphical thing here, you know When we start coding our programs start at the first line go all the way to the down They just go in order. They do every single command in order Once we start adding conditionals, we can get to where there's a choice and that's what these if statements do So if it's green go this way and print that's correct. It's black. Go this way print close etc etc and then So let's enter and see what happens So you can see conditionals. Yes, that is correct Because I typed in green the next Control structure is a loop now. This is really Actually, I find that this is the hardest topic for my students to learn. This is one of the ones they really have trouble with and I can kind of see why It's just you have these repeated sections of code And you have to understand that the code then instead of going down and branching it repeats A certain number of times in this case zero one two three four five it repeats five times This one also repeats five times. It's just a different structure. So we've got four loops We've got while loops and other languages might have a do while loop or something like that But in python, we've got four and while so I'm going to go ahead and run that and uh So you can see this does a little bit of math for us. So five times zero is Zero five times one is five, etc And then with the while loop, we're actually counting down So 10 times five is 50 10 times four is 40, etc, etc So again, this is the order that I teach this subject in I know I've taken classes where Functions were actually taught before control structures Personally, I don't think that's a good idea But apparently somebody did and maybe they know more than me I don't know But based on my own experience teaching coding for God knows how many years This is the way I do it And the next thing is functions Functions organize your code into a functional block So you're taking related actions or a single action and putting them into one little code Box for lack of a better term So you can see over here functions are often referred to as black boxes Because we don't need to know anything about What happens inside the function? All we need to know is what? Values and what type of values? A function accepts so in this case Is even is going to accept an integer And it's going to return true a boolean So if it's Even return true if it's not even return false So I didn't have to use this particular way of doing it It doesn't really matter how I do it What matters is that I know to interface with this function I need an integer going in and I'm going to get a boolean coming out That's all I need to know So once I've created an is even function I can use it forever in my program What's great about it is as I said it's reusable I can actually take this function out And put it into another program And it's going to work just fine And that's that's the one of the beauties of functions You can build up your own little code libraries For the things that you need and do often So you can see here I have Testing the code Print is even 42 So 42 becomes x or x becomes 42 42 percent to it's the modulus Equal zero so it will return true Again, if you don't understand what this means Watch my introduction to coding video So let's go ahead and hit enter and see what we get We should get true and false Because 42 is even and 43 is not So now once my students have learned these basic programming structures We then start looking at different data structures In coding And data structures are there to hold The primitive data types in groups And so, you know, let's say I have students in my class And I don't want to make student one equals, you know, Bob Student two equals to two student three equals Jason, etc, etc I want to put them all together into one Like one data structure so it's easy So you can see here I've got a list And on the list is the names Greg Grant and Bob Who are the members of Husker do And I can then print out all of the names Or I can access each name by its index So computers start at zero one and two So if I want to print Grant, I would print names one And this list can be as big as I want it I don't have to know ahead of time how many items are in the list I can just add to it as to my heart's content And if you look over here, the data structures that are built into a language Are specific to a language So in Python, we've got lists, tuples, or tuples, not sure how you say it And sets, and we have dictionaries So other languages might have these, they might not have these They might have extra ones Or they might have none, if it's a really primitive language And then there's other data structures that we construct Again, some languages have these built in Some languages do not So there's stacks, queues, binary trees, and linked lists These are a bit more advanced coding, I don't know, coding programming structures Or I should say data structures, sorry, not programming structures But depending on the language you're using, you'll have some basic types And then from those basic types, you can build the other types If you know what you're doing I highly recommend data structures and algorithms, fascinating stuff So, but in Python, like I said, we got lists And dictionaries are the two ones that I talk about most A tuple is just a list, but you can't change it So once you create a tuple, it is forever that And sets are like lists, but you can't have any repeat objects So for example, I could do this I could have Bob on here twice Because he plays guitar and sings, for example But if it was a set, you can't have repeat values And that's just like in mathematics, what a set is in mathematics And then dictionaries are kind of like lists A student of mine a long time ago said dictionaries are like lists on steroids And I thought that was a nice way of putting it So in a dictionary, you access values based on a key And then you've got a value So I've got capital cities, so Japan and Tokyo South Korea, Seoul, Romania, and Bucharest And I chose those three cities because those are three places that I have lived in my life And so if I wanted to print the capital of Japan, I would just print capital is Japan Up here, it's a number. It's an index Down here, it's a key So that's kind of cool So it's actually a very, very useful data structure that we can use Let's go ahead and hit enter and see how that works Okay, so we got lists And then I printed out grant, which was names one And then I printed out Tokyo, which was Capitals Japan Sorry, my voice is a little cracky here today I don't feel bad. I think just the air is dry because it's winter So yeah, so that was data structures So the next one is classes and objects And this is one of those things that is really difficult for beginner students To wrap their heads around And as I mentioned earlier Classes, well I should say objects Contain primitive data types They contain data structures So, and they also contain their own functions, which we call methods So these things are called attributes and methods So what this lets us do is just like with functions Where we put everything into a box Classes and objects are like These functions and all these things combined into one much bigger box And it has the same thing We can access the attributes We can access the integers float strings Bullions of a particular object We can run, we can put loops and functions and called methods again Inside of classes And it just wraps everything up into a nice package Again, that is reusable Interestingly enough, some languages don't even have classes So for example, C does not have classes It does have something called a struct, which is like a class But it only has attributes You can't do methods or anything like that And it has a few other, you can't, you know, it lacks a few other features But basically it's C doesn't have what we would traditionally consider to be a class Python has classes, but you don't have to use them Java has classes and you gotta use them So yeah, it's kind of interesting the different approaches that languages take So as you learn more about different languages And, you know, take a course, for example, in comparative programming languages You can see all these different things about languages and how they function So the example I did here was I made a class called a dog And this is called the class constructor Where we initialize our object Again, if you don't know what I'm talking about, that's fine I do have a really good video about how classes and objects work And I'll try and put that in the link down below And then so I'm going to say a dog by default has a name And when I create the dog, I just want to say dog so-and-so has been created And dogs, of course bark a lot So I can take a dog and I can have the dog bark And in my case, what barking means is that dog says whoof So what I've done is I've created two dogs, one called Lucky And Lucky is a dog named Lucky Now, I didn't have to put Lucky here, I could put L I could put H, blah blah blah The computer doesn't care This is for humans, so it's easy for us to understand And then so Lucky was my first dog ever He was a beautiful black Labrador retriever And I still miss him And Bella is my mother's current dog And she's adorable And so what I've done here is I've created two dogs And then I have Lucky bark and I have Bella bark So what I've done here is I've taken some attributes So I primitive type string Added it to a dog class So every dog is going to have a name And I've taken a function And in this case, like I said, usually we call them methods when we're associated with classes And I've created a function or method that works with this object And then I can say object dot method And then it does whatever we say So let's go ahead and run that And we see dog Lucky created Dog Bella created Lucky says woof And Bella says woof You know, Bella's voice is a little bit higher She's very tiny So yeah, that's kind of the order that I teach this subject in This is what I do with my students Again, coming back over here There are three different ways that I show the students, at least in my class, to interact with computer programs on their computer One is what you see over here, which is the terminal Where it's all text based And you're just inputting letters and symbols And the computer is printing back out to you Although it could play sounds and things like that The next would be graphical Where you have text and images on the screen You can use a keyboard, mouse, joystick, etc This would be like something like one of my gaming tutorials Such as Space Invaders or Pong Where it's not a little text screen But you're actually printing graphics Or not printing, but you're displaying graphics on the screen And the final one is graphical user interfaces Where we have windows And we have widgets such as buttons We have labels And we have drop down menus and things like that That's what a normal program looks like So like this program has a little This is a drop down menu It's got a title It's got a window It's actually got some text stuff in it So you assemble a GUI that way And then when you click a button A function is called in the background And it does stuff So these are the three ways, at least The main ways that I know of Interacting with computers And interacting with computer programs I think, as far as I can tell I think everything's basically a variation on these three And so, you know, I usually The first few units, we only do terminal stuff And then once we get to functions I start doing GUI stuff Because you need to be able to do functions To create GUIs And then, again, this is just the order That I do things in As we are going through and programming And learning new things We're always returning back to previous topics So I might make a loop And you have to pull out all of the capital letters From a string Using a loop and some conditional statements Things like that And then later we add functions And all that on top of it And then a final kind of topic That I hit with my students Or I tried to Is algorithms and complexity And I'll just give you a quick example of that So earlier We listed three names Greg, Grant, and Bob So imagine I want to know You know, is Bob on my list? Okay, so if I don't know So let me go ahead and hit enter here And see what I did with this So I started out with Greg, Grant, and Bob And Bob's index is two Then I sorted this list In alphabetical order Bob, Grant, and Greg Okay, now Bob's index is zero Now think about this For me to know Bob's index I have to search this entire space So if I start here Is that Bob? No Is that Bob? No Is that Bob? Yes I found Bob So it took me three tries To get to Bob Now if this list In this case where the list is sorted I go to Bob I just happened to find Bob On the very beginning of the list So it only took me one try To find Bob Now computers are fast But imagine this list had a million items For example, all the people that live in Toshimaku Where I live in Tokyo Okay I don't know if there's a million people But there's a lot Tokyo has 30 million people Greater Tokyo has 30 million people There's probably about a million people in Toshimaku Maybe two million, I don't even know But the point is If you're searching through a large number of items If you have to go one by one It's going to take a long time Relatively speaking, of course And if you're doing lots of searching It could take longer and longer and longer So algorithms in complexity deals with You know, how do we do things like sorting? How do we do things like searching Efficiently with especially with large data sets And certain types of problems that can't be solved Simply And so What trade-offs do we do With certain algorithms for doing these things So there's time complexity Which talks about how long something takes And then there's space complexity Which talks about how much memory A particular algorithm takes to run So just I'll just I'll just say one last thing And then you guys can you know Think about this for a while So again here Gray Grant Bob Bob was two Here Bob was zero So If we get lucky It's the first item And it only takes one search But if we're not lucky We have to go all the way to the last item To find that particular person Or whatever it is we're looking for So the average is It would average of It would take you know I guess Two searches I think it's n divided by two Or n plus one divided by two I can never remember Anyway So it takes that amount of time On average to find it But if we had Say we had a billion items Which you know in this age of Big data is not Unlike not impossible So we have a billion things to search through And we have to search through it one by one So on average it's going to take 500 million 500 million checks To see if we have that Because it could be at the beginning It could be at the end But it'll average out to the middle So if we do what's called a linear search And in But if we sort everything If everything's sorted I won't go into too much detail on it If everything's sorted It will take a maximum of 30 tries If we do something a Called a binary search So we can change that 500 million Search time complexity Down to 30 By using a little bit of sorting And using a little bit of clever programming So that's a topic for another day So Yeah, so that's kind of the stuff that I teach And I think that's a good order for beginners I think this covers About what you'll learn in CS 101 And CS 102 In most schools Yeah, some schools you may or may not do Graphics and GUI stuff You may just do the more You know Programming with a terminal type stuff That's a very traditional approach I like to use graphics and GUI stuff If I can just because it's more interesting And it gives you a bit more of a context For some of the things we're doing And then beyond that There's stuff like software engineering With design patterns and agile development Things like that There's all kinds of crazy libraries And modules available I'm learning some of these myself now In grad school But again, as I mentioned earlier Students have this weird tendency To want to just jump in Okay, I want to use TensorFlow I've never recorded before They say I want to make an app To call my friends on the internet I'm a new programmer You know, I know I'm coding for like 20 30 years at this point I have no idea how to do those things So it's great that you want to do stuff But you really need to slow down And learn these basics first Okay, and then there's How do you deal with servers and clients There's databases How do you deal with different platforms Coding is a huge, huge, huge world And the basics here are important And you need a very strong foundation To be able to build up to all of these other things Now again, Python especially Makes a lot of the stuff very simple It takes the complexity away It abstracts away the complexity But it's really, I think, important To know the basics and to know them well So anyway, we've looked at variables and data types Input and output, control structures, functions Data structures, classes and objects Terminal, graphics, GUI And algorithms and complexity I think if you take the time to learn these things And to learn them fairly well You'll have a very, very solid foundation To build your coding future So don't, there's no shortcuts You know, take this stuff seriously Learn it step by step And you will have a very strong coding future I'll leave some links down below To my tutorials that I mentioned in the video And if you have any questions Just put them in the comments below And I'll answer them as my schedule permits Take it easy and keep on coding