How To Think Like A Programmer

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
so what I want to talk about tonight what Calvin asked me to talk about so if it's a bad idea it's his fault was a little bit about how Python fits in the space for beginners now I know a lot of you are not beginners especially if you're looking for work maybe it's better not to be a beginner at that point but even if you're not a beginner is there anybody who is who's brave enough to say so you're just learning Python yes you and me dude okay excellent great this is for you the rest ease people can hang out but actually this would be useful for all of us too because I don't know about you but as I've not gotten smarter but I've gotten grayer and so people expect me to be able to help them learn how to do things and as you become a senior dev you're always ending up having to teach people am i right most of us are not good at that I'm just saying and you know I love to go on the learning program forums and Reddit and so on and it's comedy gold so what are we gonna talk about we'll see how you can think like a programmer even if you're not sure you can and how does each beginners with my fun you like that look at that whoo that's fun alright so you don't need to know much more about me except here's my favorite thing that Calvin didn't know I used to be a special ed teacher yeah I know it was actually severe disabilities in North Central High School that was the best best preparation for being a computer science teacher I could have ever had it really was and I'm not being facetious here I mean some of my students are here they're like yeah you're true yeah because I learned how to teach I really learned a lot about teaching and I'm still learning about teaching 20-some years in I'm learning a ton about teaching I actually I think programming is hard do you agree see this was the interactive part yes okay programming is every bit as hard as most people think it is I think teaching is harder I honestly do I think that's the more valuable more difficult more rare skill which is funny because there's a lot of people with the title who don't have the skill so yeah yeah yeah yeah you know all that stuff goofy dude that's the most important one all right so how smart are they oh I didn't do it I didn't do it Nick can you run outside I need a rock huh sure will work I'll use my shoe that's the scary thing they knew where I was going with this okay who's got a good gaming rig okay yeah what you got tell us your specs it doesn't matter excellent that's a good machine good machine okay normally I have a rock but I'll just use the shoe how smart are they you thought I was talking about the students didn't you no I was talking about how smart are the computers there's that gaming computer and there's my shoe which one's smarter it's a tie it's a tie and if you don't get that we're done that's the most important thing about learning how to be a programmer don't you agree now I'm gonna have to take the other one off for a walk in circles all right so how smart are they not the people that's never the problem the people who I teach usually are super super they're really really clever and bright and wonderful that's never the problem I've not encountered anybody yet who couldn't learn to program if they wanted to I've met several who don't want to but how smart are they I'm not talking about the people I'm talking about the computer see the hard part about writing a computer program isn't trying to be as smart as the computer it's trying to learn how to be as mind-numbingly stupid as a computer that's the hard part and until you can understand that you'll never really be able to write programs do I get an amen yeah yeah all right so learning to program is hard if you're just doing it now do you agree with me it's hard and in fact I'm still learning to program my bananas for 30 years I'm still learning I'll let you know when I figure it out I still feel like an idiot all the time am I the only one all the time I like walk out of my office is like why do people pay to read my books people are actually paying to see my class if I can't even get this stupid thing to work her my wife is like get back in there and get it working she is loving she is awesome learning to program it's hard why well program feels different than other skills doesn't it especially to a beginner yeah I'm good at cars but I don't know this stuff languages are scary right they see codes code that sounds like it's a mystery you're not supposed to know what it works how it works so the language is scary there's codes you know you think the language is scary the environments are scary we have these IDs and you know I look at modern development and then tell you 25 different steps you have to do before you start opening your first program that's insane absolutely insane well first you have to develop your environment especially JavaScript don't get me going on that environment right now well the scariest thing let's be honest sometimes it's us yeah because we love to talk in jargon we love to talk about all these things and we love all of our really fancy ideas we love to show off what we've learned and that might really freak out a beginner yeah I'll show you specific examples as we go don't you worry most beginners have failed a lot yeah and a lot of these are people who are pretty smart they're not used to failing let's say these are people who did good in school and they failed and then they fail again and maybe they've gotten bad advice and they follow that advice and they fail and they feel stupid and why would you go back someplace that makes you feel stupid all the time that's a good that's a good question it's super easy to get bad advice isn't it well do some of that and you know good programmers are often good people but not always good teachers have you found that to be true I've been one of those good programmer not good teacher I've been a bad programmer bad teacher too so this stuff is hard I love this you know every day I get to find out some bad beginner advice here's things that I see on forums and I've actually said probably all of these just start with a simple game you know you want to learn how to program just start writing a simple simple game like what kind of game Oh something super easy like Tetris oh if you've ever tried to read Tetris it's not simple or you know just write tic-tac-toe oh dear or this start with C++ that's what they use in industry I especially love that in the gaming community you know you really need to learn C++ because that's what they write game engines in I'm like you are out of your flippin mind I love C++ but you're gonna begin with that are you kidding me that's a super bad idea because you know what's gonna happen C++ awesome language you're gonna feel stupid the first 15 seconds aren't you if you've if you've tried to teach a beginner in it actually C++ starts out ok C and C out how hard could this be yeah let's talk about memory allocation huh yikes if you use Visual Basic you don't have to code until the very end of the project that's one of my favorites you know my visual basic program is all done except for the code I love that one oh dear yeah I used to teach that thank goodness I'm done the best way to start is to pick a problem you want to solve I like this one I like this advice except it's terrible because C you know I'd like to solve world peace is that the first problem I should try you know having goals is good but if the goals lead to inevitable failure and defeat maybe we should pick a subset of saving the world first you'll stay motivated if you work on a real-world problem until you feel like an idiot and leave because here's the problem with real world the real world is messy isn't it and so I'm not so sure that we always want to be focusing on real-world problems to start here's things I wish I'd been taught when I was a beginner and I've only learned this after Bui twenty thirty years of teaching this and I'm still learning it programming is not about languages this is the question I hate the most on these forums right reddit learn programming I'm there every day to PI look for me what language should I start with and I like I have to stop because if I had quadruple size caps-lock I would use it wrong question that's stupid question and here's the great thing you're gonna get reams of advice about it all of it's stupid programming isn't about languages sure you're gonna pick one but the language ultimately doesn't matter that much some would make you feel better earlier some will make you feel stupid or earlier public static void main string args but the language doesn't really matter programming was never about languages you know here's my guys in the back right in the first year of our program I teach for programming languages and you know the funny thing that part's not the hard part that's what they tell me am i lying now no ok good ok good I'll still pay you um yeah they think that's the hard part no the hard part is we keep changing paradigms the hard part as soon as we know one language I start talking about something deeper that we can learn another one pythons not a good language to teach direct memory management in for example because it does it for us but if you're a computer scientist you better know what direct memory management is that's when we're gonna work to in C and C++ make sense yeah mmm and free yeah you guys don't know that your Python people okay good most people think that programming is about memorizing I'll never learn all those codes and I'm like yeah neither will I I don't know what you're talking about I don't memorize syntax I couldn't because I used too many languages you know on a typical day I'm helping debug code in six seven languages there's no way I could memorize that okay this is a good one most programming isn't about math you know I'll never be a good programmer I always hated bad first of all you hated math class I'm not sure you've met math secondly until you get into data science gaming and a few other specific areas you could do fine in programming without using a lot of calculus right who use calculus today that's what I'm saying okay you did you're very smart and there are places we need it and certainly you know I use linear algebra several times today because I taught a game programming class but I might not need it every day you can get started without math and here's the fun thing when you start programming you're gonna realize the kind of thinking you're doing is the kind of thinking that math was trying to teach you in the first place so there you go programming languages I love this one programming languages are simpler than human languages I know this because thirty years ago I tried to learn Japanese and I completely failed until very recently when I tried to learn Spanish and now all the Japanese is coming out what has this Tomodachi son I'm the only person in the world who's fluent it's Bethany's human languages how much vocabulary do they have lots how many words like a hundred thousands okay how about the syntax rules how complicated are they oh dear Lord yeah you know my family is all learning Spanish because my daughter's going to school in Nicaragua and and you know there's tenses I've never even heard of you know past future wonderful undescribed pretty pretty Cori sense I don't know what it is but I don't even understand it computer languages how many words do they typically have in the vocabulary about a hundred how consistent is the syntax painfully programming languages are actually designed to be much more sensible they're not as flexible poetry and programming languages not quite as successful except Perl of course it has blessed kill and die those are functions in Perl I could tell you my Perl joke right so a thousand monkeys on typewriters eventually one of them would would type Shakespeare the others would alright Perl code there's not many places you can use Perl jokes that's what I'm saying yeah programming really isn't about the things most people think it is here's another one programming you know I can't type fast enough to be a programmer I've heard that one actually probably you should be typing slower right how much of programming is typing close to none of it close to none it's really that the shoe again it's about explaining things to the idiot computer that's what programming is how we think about it that way it's actually not quite so frightening code isn't about language here's what I'm beginning to learn after teaching this for many many years because I have taught beginning programming pick a language Perl yes I taught beginning programming in Perl and basic and Pascal and Loco remember logo no some of you don't and scratch give me a language C C++ Java I've taught him all its beginning languages and they started to rub them together I realize there are some common themes it turns out when I'm teaching a beginner how to go from not a programmer to a programmer there's really about seven or eight concepts depending on how you look at them you get those and you're done and those concepts are universal across languages that's pretty beautiful isn't it now true if you know multiple languages you know this to be true right your first language is hard your second language is harder isn't it because you thought you knew the truth your third language it's like dude I'm seeing similarities here by four or five you know you're doing you're doing the was it was it oh yeah you were saying they asked me to do a project Empire so give me a weekend yeah it gets that point doesn't it because we see these these consistencies coding is only about eight main concepts I'll show you my favorite few how's that they work in the same way in every language when we're trying to teach people how to code don't teach them code teach them English or teach them in English the secret isn't code the secret is algorithms and data that's really what we're here to teach and of course let's pick a language that makes that easy I nominate Python if it chooses to run it's gonna win we write out the concepts first and then we convert to code later this is so key when my students come in to me and they're like ah I'm so messed up the first thing they do is sit down and they open up their computer and what do I do I shut it on their fingers why if you're lost in coding it's probably because you shouldn't be coding yet it's almost always the case you write out the concepts first and convert to code in fact I will grade your paper if you wear the beautiful algorithm and not a line of code you'll still probably pass doesn't happen often because if they write the algorithm well the code comes if you turn in beautiful code that runs great without any comments in it I give it back that's how important this is after midterm anyway so most beginners this is so amazing when you when you if you are a beginner and I still am you get to this point where you think you don't understand how to write the code I can't tell you how many times people say I know what I'm doing I just don't know which code to write no no almost every time somebody says I just don't know how to write it no that's not the problem the real problem is they don't understand the problem they're trying to solve they're jumping straight to coding without understanding algorithms and I get that cuz coding is cool right you look like a hacker I showed my son hacker typer you know that site hacker typer calm oh you need this hacker typer calm all you have to do is bang on the keyboard furiously and it looks like you're writing C code and if you hit the right control sequence it says like you're in NATO or whatever yeah it's awesome because that's what all of the students think they're gonna learn how to do anyway yeah and now you're all going there I love it the real problem is that beginners don't always understand the problem they're trying to solve they try to figure out how to do it before they try to figure out what to do and really experience people like us we do that too don't we every day every day all right here's one of my favorite ideas and then we'll actually dig in and do some sound good comments are could wait alright so we all know what comments are for comments are there to explain code to other programmers you agree sure sure which explains why we never write them doesn't it because if the comments are there first of all it's their own dang fault if they can't understand my code secondly I don't want to explain what it does until I'm sure I know and that may never happen well painful painful little giggles there yeah cuz this is true right we're all here and you know I gotta hit this thing delivered man it's deadline I'll do my best to get the comments in at the last step but I gotta get it working before I can worry about that yeah so comments are there to explain the code to other programmers or better yet yourself because a week later you're like crud what does this do no no no I finally learned the truth comments are not there to explain the code to programmers code is there to explain the comments to the computer that's profound but that is that's all I got good night I'll see ya code is there to explain comments to the computer at least for beginners but again I still consider myself a beginner it writes your algorithm first you got that algorithm first working it's beautiful and then how do you know it's done it's like a turkey right the little thing pops out no how do you know that an algorithm is done you look at every line and at this point maybe you even decided what language you're gonna use and you say I can do that I could do that I could do that look better look that one up break it up into smaller things I could do it I could do it I could do it I can do it at that point now we can start thinking about code that sounds really meaning doesn't it my students think so too until they do well and they all learn more than me so now they don't think it's so bad this is important idea all right so let's go into I said there were only seven or eight main concepts let's do our favor first four how's that No okay it's been nice seeing you guys here's the way I like to think about it because really algorithms you can say that and people like ya but let me show you exactly how we like to think about these I actually have one chart that I'll make and it was uglier than the slide show so you know if you want it I'll give it to you but I have one chart and I say you understand this it's an HTML table it's that ugly you understand this you've got programming oh you want to do it in Java one second change it all okay great I changed one column so I just rebuild that table for every language we teach it but here's the ideas now the first idea is about variables right variables about data so those of you who are really beginners today's our moment if you're not a beginner garden oh that's right but someday you're going to teach it to someone okay and the real issue isn't just a variable okay it's a place of memory to hold data great we know that but here's the interesting thing about this approach to learning is that I say first thing you need to know is there is such a concept as make a new variable and when I'm running an algorithm this is one of the things I can pick what am I going to do I'm gonna make a variable so that's on your drop-down list of things you can do make sense there's only about eight or nine of these really but when you say that as soon as you say I'm gonna make a new variable some questions should pop in your mind oh dear hey there's some HTML code why did that test die alright so some questions should pop into your mind or it doesn't matter what language you're in no same questions anytime we make a variable I guarantee you're gonna need to know what's its name what's its type what sort of data does it hold those of us who've been programming for a while know that computers are a little fussy about that you know we have integers that don't have decimal point stuff and we have floating-point numbers that have that and then we have strings which is the much cooler way to say text and then we've got other stuff too and it depends on which language how fussy you are about that sort of thing right if this was a Java group they believe you of strict rated types baby we're Python we're like man it's all the same but does it still matter what type something is even if maybe our language isn't too fussy about it we shall see initial value what's its starting value so would you agree whenever you make a variable in any language you think of these things there might be some others like scope but I'm gonna save that for function scope doesn't mean much if you don't have functions yet so whenever I make a variable that's what I think do you agree okay here's where you say yes yeah yes please go home okay good good thank you so how do you write in out an algorithm this is the part I'm proud of okay that's not the part I'm proud of when it works is the part how do you write an algorithm here's the beautiful thing you must write in English no coding allowed unless of course English isn't your favorite language and Swahili whatever cool awesome create whatever it is I don't care but your sentence has to answer those questions it has to answer the question what's its name what's the starting value and what's its type that's your algorithm does that make sense so when we're teaching a beginner to make a variable the first thing they need to know is I need to make a variable and then the second thing they need to know is what questions should I always answer when I make a variable that makes sense and then when we do that honestly that's all they need but see if I could get away with it I wouldn't even teach a language yet but they don't believe it's real coding unless they're typing somewhere so fine we'll do it that's how we write this in Python name gets an it Val type huh you're on your own but that's how we do it in Python so I can live with that can you live with that yeah sure because we're Python programmers so that's good so that's one of our concepts here's another concept I mean it seems trivial doesn't it but it isn't it isn't output right what's another thing I can do well I can tell the users stuff I'm gonna start here with the command line console because life is easier there isn't it we're in charge I mean in the GUI the users in charge and who put them in charge not me but output is pretty easy there's only one thing to worry about what message do I want to send the user and of course outputs usually text isn't it yeah outputs text so that's pretty easy and we could write an algorithm for an output line to couldn't we don't worry there's a quiz coming I'll put the text message okay that was really easy yeah your code yay for Python 3 yeah [Applause] system dot out dot print line no no no console.writeline no it's easy it's pretty except I always yeah see I think printer what's aperture I don't know you know I still mess up the parentheses for is sometimes cuz I you did to seven for a long time wrote a whole book into so the parentheses sometimes throw me but I could do this now how much are we worried about the Python syntax have you seen how much we've stressed about that why not because you all know it but why because that's the part we can look up how do I do it in this language that part Google will help us with woman if you turn to Google how what problem am I trying to solve you're gonna get some very scary results but if you know what you're trying to do you know I'm trying to output text you can say how do I put text in Python three and the chance of sorry you'll get something pretty close to this yes so the coding part is the easy part in algorithm part is the hard part alright so we're getting to the point where we have enough of these tools we can start to put together a real program there's a you know input now input I like talking about input because this is the first one that really starts to talk about the real complexity of coding isn't it because see all of the other things were atomic they could kind of stand on their own but input is really mean input has like dependencies doesn't it I mean you think about it when I when I input something here um tell me the answer tell me the answer come on 42 that's a good one I like that yeah I'm coveting that t-shirt it's not fair for me to ask you the answer if I didn't ask a question is it it's never stopped me as a teacher but if I am asking for an answer I should really give you a question so an input applies that there was some question asked of the user it may be in that statement as it is in Python it may be another line it doesn't matter much but somehow we're gonna ask the user a question well okay now throw me the ball come on throw me the ball come on you guys can help throw me the ball please yeah you have a ball threat you know what I should have done I should have put up my men I shouldn't ask for somebody to throw something if I'm not ready to catch it yeah input you have to have a variable to answer to hold the answer you have to have a question that you asked them so the crazy thing about input is it should never be the first line of your algorithm you see on his hand it doesn't make sense because there's there's like prerequisites so you need to either in the input statement itself or in another statement you need to ask a question and you already need to have a variable in place that can catch the answer well that makes a lot of sense doesn't it and what does that have to do with Python syntax nothing that's a different problem and an easier one isn't it that's an easier problem okay so how would we do an algorithm again anyone you want any line of algorithm as long as it answers those questions makes me happy ask the user a message and store the answer in variable beautiful we good with that you want to see code you've seen the code but it's easy variable gets input message yeah but you see the point I'm trying to make when we understand the concepts the code itself becomes actually at some point and this is why we don't always write comments right at some point this is more clear than that but not for a beginner not for a beginner so a beginner has to do this part for a while before they can jump straight to the code does that make sense because we've forgotten that sometimes and to the beginners that we're trying to help this looks like arrogance it's not it's forgetfulness but we can see there's not a cleaner way to say that I really can't think of an easier way to say that in any of the languages I used thank you we don't but we forget that it's not obvious to beginners okay that's enough we can read a program can't we sure we could with just that all right I'm not gonna actually make you write it because I want to get to some other stuff but here's the program we would write now for real life I would stop right here no more we've learned plenty you can't make me teach you another line of code because we would stop we get out paper and pencil and we would write some algorithms together in groups not by yourself if you're really confused find somebody who's feeling very comfortable and make them uncomfortable and we write this out and if you turn on a computer I will slap the slap it shut on your fingers cuz I don't want computers right now I want brains those are much better computers anyway right and so we write this no code that's really hard for those of us who think in code isn't it yes I sometimes do dream in code it's terrifying especially when my dreams involve memory leaks it's a bad bad thing honey just turn on the vel grind she's like what's up al grind never mind never mind algorithm only I'll go ahead and do it for us there's my first try you see what I did here no code create an integer variable for X created an integer variable for Y create an integer variable for some did I answer those questions yeah okay I ask the user X and put the answer in X ask the user Y and put the answer in Y put X plus y and some tell the user the answer is som this is awesome okay some of you know there's a problem and some of you are like seriously I could have just written this right but you're not a beginner anymore if you're a beginner you need to write it this way first now here's the beautiful thing about Pi a Python right we're a half a step away from Python because python is beautiful except for a few warts come on name equals main that's pretty stupid I love Python but that's it's work come on it's still there and the whole self oh please if you're gonna require self as a parameter then tell me the right number of parameters when there's an error in the function because my beginners are freaking the heck out it says it only has two parameters when there's three basic but there's four okay so first we just write this as plain text paper-and-pencil is better than uncut whiteboard is my favorite lipstick on the mirror cool blood on the wall don't do that but we come up with a plan then we take the plan and now we convert it to comments now you could put it in your text editor which one I do not care if you're spending a lot of time stressing about it wrong one I'm actually still a vim guy I'm that nerdy I know but I'm not gonna impose that okay second class I do but but in the first class no no I'm not gonna make you do that but I want your editor out of the way I'm not a huge fan of syntax highlighting that doesn't solve the real problems does it or a code completion and all that stuff that doesn't solve the real problems that solves the easy ones the real problem is how do you think well and the cleaner your editor is the easier we get there this is a pretty good answer isn't it is it code well technically we could put it in an editor and it wouldn't crash um it's a great algorithm okay at least it's a good algorithm would you agree no no I'm sad okay I like it now the next step okay now we can put in code and so every line and this again is something that we love to teach our beginners or I do everybody else hates it and and that is okay now that you've got those comments one line at a time you look for that comment and you tell me how to write it in code go crazy with Google if you want do it of course I taught this in China and they said what's Google okay Baidu good luck that's tortoise about that man teaching Java in China please teach advanced Java in English you've got one month I got there and realized they didn't know basic Java or English and that was the translator yeah it was crazy so now each of these things I can say dude I can write that I can make that and in fact this is the first time that it even matters what language were in you know maybe I'll go to the Java users group I'll just change this slide except you know I can't make the comment about public static void main string args which is huh oh yeah it's it's coming yeah I'll show it to you yeah I've got a yo-yo don't you worry anyway so we can take each one of these things and we can convert it to code in that beautiful isn't it beautiful yes that's beautiful and then of course we could test it and again I'm not too fussy if you don't have a copy of Python on your own machine right now that's not a big barrier I love some of the online environments Python anywhere love that one in fact I've got at work running on there so you don't have to install it on your own machine if you don't want to no good reason not to come on you're using a bun to write you've already got it [Music] here I happen to have it running I think and I warmed up pi okay so there's that same thing I just copied and pasted shall we run it oh I am all the Twitter here we go okay come on give me some code yes I don't know what that is but I think it's funny okay x 3 y 5 this is going swimmingly 35 oh dear really should have tested this shouldn't know I knew what was gonna happen see look at my next slide stop it stop it stop it stop it ok this is where we all go wrong this is where we all go wrong first of all the first thing we do failure is a wonderful thing if you don't like failure you're in the wrong business because how often do we have miserable crashes a day I'm in it I mean it happens all the time right if you can't be big about that then you're in the wrong job I don't know what job is good for you but this one is it because it's gonna crash a lot but our failures are opportunities for us to grow and we have to have a good attitude about that and you know what we should teach debugging the very first moment because there is no programming that isn't debugging isn't it I mean how much of programming is debugging and how much of it is actual programming it's pretty much all debugging isn't it begin debugging now now here's where everybody gets in trouble one thing we all like to do especially those experienced people as we jump right at what the answer is right we start solving this sucker and often because we have a lot of experience we do it very well it really pisses the students off when I do that I don't even see it we're walking in the hallway and I can tell them what lines wrong and I'm usually right that really pisses them off except at least their coats working because I've given this assignment for a few times and I know exactly why it's acting stupid but did you tell it what to do incorrectly that's what most beginners think I must have typed the wrong code because they still think that programming is about writing codes that's what they always assumed or did you tell it to do the wrong thing okay we can think about this example did we tell it how to do it wrong or did we tell it to do the wrong thing yeah one of those we don't know that's a beautiful answer we don't know I don't know is the best answer any programmer could give me because if you do know and it's not right you don't know this is one I hate I just have one simple problem professor then why are you in my office if it was simple you would have solved it you've done something boneheaded I know and I'll help you but don't pretend it's simple so often we think that we just did it wrong but what happened is we did the wrong thing maybe with a good conscience but beginners almost always assume it's an implementation problem when it's almost always an algorithm problem is that the case here almost it's an understanding problem and that's ok that's ok that's wonderful that's gonna happen every day and you know what I could have prevented that I could have taught you how to convert to an int first right but I don't want to because the beautiful thing is embracing those isn't it embracing the fact that when we learn how to code we fail all the time and boy do you wish you learn this slide a hundred years ago I still don't know how but I've been yeah Adi buggers are good I like debuggers although you can depend on them okay this is my mr. Miyagi ISM of the day best way to debug code not have bugs and as although it's facetious is it true yeah the best way to debug your code is to write code defensively sub bugs don't creep in that's very hard to do it takes a lot of experience there's other things you can do though bad implementation if I just did it wrong I could Google that if Google's not getting you the right answer you probably don't have bad implementation you probably have bad algorithms or a bad understanding of the problem space those are much harder to find in Google aren't they bad algorithms you can't look those up there's probably something you're not understanding does that make sense something's not acting like it like it's supposed to and that's when a debugger the idle debugger is good again I'm still a PDB kind of guy I'm just that old school cuz man a command-line dude I can do a lot but there's something I'm not understanding going super slo-mo look at that thing print stuff out see if you can find out something that you're trying to do is not doing what you think it is you know are there some tools that I can look at to help me of course the debugger is good in this case you know we could we could start looking at hey isn't there command to find out what type something is in Python yes this is called type but here's the thing I makes me crazy because I do it every time oh yeah no here's what you here's what you need to do right we start solving problems we don't understand how often have you done that today we are constantly solving problems we don't understand and how often do we make a better how often do we make them worse and so don't start with a solution unless you're using it then just okay make it a new branch and then go ahead but don't start with a solution because you're gonna mess yourself up aren't you and I have people come to me all the time they just swear swear python is broken because it's not working and it should okay there's something you're not understanding and there's nothing wrong with that but there's something you're not understanding and your assumptions are probably a big part of the reason you're not understanding things you're assuming things that aren't true do some detective work sherlock let's figure out what's going on let's get in there and find out what's happening there's lots of tools for that you got to start by understanding the problem a lot of times I'll turn off the computer I'll be like yeah turn off that computer here's the whiteboard marker when they move my office they were going to take away my whiteboard and my bookshelves and I said you can have my computer true it's your story and they were like you're nuts okay we'll give you the whiteboard because we you scare us a little so what did happen here okay now you can say it's easy to assume the plus sign is broken dang it this thing doesn't even know how to add that's a normal assumption though isn't it how stupid is this now that's not really the problem those of us who are experienced see we're feeling superior because we already know how because we've already felt like idiots long ago when we forgot it or we're just kind of a little you know it we've all made this one haven't we the plus sign is not really the problem what's really the problem you know Python that said interactive mode I love that right if I try to do Python plus meetup what's it gonna say Python meetup there we go wait a minute wait a cotton-picking minute you can't add Python and meetup can you okay be careful here because you know I'm about to slap you because somebody wants to say well operator overloading is a form of polymorphism and it's actually concatenated rather than adding because it's automatically detecting that these are strings and not integers yeah slap you with a wet fish for that when you're around beginners all right when you're around beginners this is the worst thing we can say because they're like yet you just switched in a serbo-croatian or something they felt stupid before now they feel worse so yes is it is all that stuff true yes it isn't wonderful when you understand it yup but do you have to understand that the first day no no no I think it's enough to say hey it's the plus sign is so smart that it does different things when it sees text and when it sees numbers and apparently it thinks that five and three is text I wonder if that's the problem can I test that right and then we google again is there a way to find out what type of data something is is there yeah is it type or type of I get JavaScript and Python confused every time I always guessed wrong the first one its type okay so we can apparently add text yes concatenation and wonderful things two or three or text we look up a tool the type function tells us what we want to know okay now we add a new tool to our toolbox you see what I'm saying now we add a new tool to our toolbox and we say cool I need a new algorithm piece convert to integer go look it up figure out what you have to do looks like we have an old in a variable and int variable and convert old variable to integer store an int variable oh look there's code for it that's all fun isn't it now we have a new tool and that's how we continue growing is as we encounter a problem we develop a new algorithmic tool to get there does that make sense so this is this is pretty kind of fun isn't it it is really in the geeky way all right I know now we can try again with a new tool notice what I did I killed my code I can't believe it took me hours to write that now we did it it took you about 30 seconds to write it it took you hours to understand it and you understood it wrong really hard to get people to throw away code isn't it like us right okay fine put it in a subdirectory but start fresh get again man I love get but start fresh because if it was worth keeping it would have worked and you didn't lose the thought process you just got yourself in a bad place so I'm gonna rewrite my algorithm now and I'll tell you the truth I wrote this wrong the first time I put it in the wrong order but before I wrote an e code I was like dude that's in the wrong order it's not gonna work you see this I'm thinking about programming before I write code because it's often easier to see the order of things see I converted to earth but now I look at that I'm like that makes sense I could do that on a whiteboard I can be the computer and now we'll put some code in will this work yeah we could prove it I can run it but it works there's branching there's four loops I want to talk a little bit about while loops though and then we'll be done you're good with that I don't know how long we're supposed to go but you know it could be the next election cycle before I'm done it's an endless loop that's the problem yeah let's just skip this one okay so you know for loops people sometimes get mad Python people when they see the way that I teach for loops because I say that a for loop has lots of parts it has a century it has a start it has a finish it has a change and you're like that is such a C++ for loop what is the matter with you and yeah and I teach for loops in Python you can see my code for Iron Range start finished change oh that is so unpack yes it is yes it is because sometimes I want to teach Python and sometimes I want to teach programming and when I'm teaching beginners I'll do this if Python uses chicken or third language we'll do it with iterators but this traditional structure lines up better with other languages but much more important it's much better for learning to debug properly because when you have a loop what are the three things you always think about in a loop well four things really first is this century what is this variable that controls the whole thing right and then what are three things about the century you need to know sing-alongs people you know this how does it start how's it finish has it changed which seems so simple right but how many loops have you had that have gone terribly wrong what's the most likely basic code structure to go wrong a loop especially if you see a boolean operator in that son-of-a-gun death two boolean operators yes yep or the falseness there gave me that one that was too easy we're gonna come back to that thought real quick anyway a while loop so what are the four things you need to know about a while loop what's the century how's it start how's it in how's it change but no that's not true Andy the while loop has only one parameter that's the problem with while loops the while loop implies a lot that it doesn't require and that's why a while loops go wrong so often don't they because if you're gonna make a while loop you were also have a holy obligation to it to think about what the Sentry is even though the while it doesn't require to you have to initialize this entry before you got there which means you have to plan ahead which means why are you writing code you should be doing algorithms and then somewhere inside the loop we don't know where you have to change this century and you have to change it in a way that guarantees that at one point you'll trigger the condition oh yeah we need a condition but you never forget that one you will sometimes make a condition that's impossible to to satisfy though won't you marriage seminar or something but no so these are the same things that are required in a while loop and that's why I teach them first in the for loop because how easy is it to mess that up now you don't do it all right here we go here's the example basic password loop leave out on this one right it exits with a positive recite result if the user chooses the right password but if they get it wrong it launches misses so if you get it wrong three times sorry about your luck sending the missiles all right we could all do this how you gonna coat it okay really how are you gonna cut it all right we'll use a compound condition right with a boolean now I love boolean variables don't get me wrong it's boolean operators that bug me because here's why because what condition do we need on this thing let's see tries is greater than equal to 3 and guess is not equal to correct yeah that's it or is it because now guess is the negative and de Morgan's law it's as a boolean variable okay take a picture cuz it go away so correct as in d pi tries to 0 keep going is true well keep going you know what I love about boolean variables there's just a not not a lot that can go wrong it's about the cleanest variable type you got right I love boolean variables I don't love boolean operators as much unless I'm working on just boolean variables with them but well keep going if this thing is true and is it it better be well I'll keep going it true do whatever code I want yes I deliberately did not do the format thing because I don't want to freak out beginners it's really cool but not today now take a look if gas is equal to correct then we'll say that's great here's the treasure and then look at this beautiful thing that's where that's where the break statement goes doesn't it now we should never write break should we I know switch statements thank you for not including those you know yeah keep going it's false that means the next time I evaluate this loop we're out how clean is that and what do I really mean by this line I don't want to keep going like that it's gonna be much easier to follow house if that rises I didn't really do Elif Elif is like a dwarf but it's taller and then the years if tries is greater than or equal to 3 then we're gonna print hey too many wrong tries launching the missiles once again we're not directly exiting the loop but we're telling it the next time you evaluate I don't want to keep going any more you know what's funny is I no the last time I wrote a while loop that didn't just say while keep going because once you get used to this man it's beautiful it is just beautiful and I read a lot of games you know game code gets messy doesn't it no could gets Messier the game code partially because we don't design for maintenance in gaming you know it's gonna be out of date and in a year so in gaming you don't design it to be maintained you designed to be fast and so you're at some junk okay eventually we'll teach all these things at their time but not today you're good with that yeah no let's just stop with this so why Python right I mean I've taken a lot of time to tell you tonight that the language doesn't matter yet it's a Python group and I do love Python so if the language doesn't matter why did we choose Python well I'll show you okay you recognize this right what language are we in old school see man this is the way God intended pointers everywhere no strings those strings are for wusses all right there's some seat and there's kind of you know how the world is too simple to really get the feel of a language isn't it so I say really we need to do hello user that is it ask the user's name and then it does something with it that's the smallest program I think we can really get the sense of a flavor of a language would you agree and would it be possible for me to take that little chart we just did and show you how to do all those things in C absolutely absolutely there C but don't worry hey Buren how you doing they see all these people in the open source world they have the best names don't they you know Vito and Bjorn and stuff like that yeah I figured that's the only reason I'm not at the top of the open source world is my name is too obvious I was gonna go with one of the sub-saharan languages with clicking and stuff my name is David Harris either that or just switch they skip the human language is all together go to Dolphin I'm sorry all right so C++ Wow at this level C++ looks like a dream doesn't it no more print different c++ must be easy yeah if you've done some yeah if and def anyone yeah yep ok C++ is pretty nice at this level but it gets hard fast all right here's my favorite right public static void main string args have you ever tried to teach Java to a beginner you've ever been to a beginner Java class that I mean every Java teacher in the world who has to teach beginners and this was me that's what they wanted in Nicaragua please teach this in Java please wave a dead chicken over your shoulder turn around three times it's a ritual throw salt type this line and they're like we do not have a chicken nevermind I don't really mean that it's just a ritual because I don't want to teach you what a static method is yet that doesn't make sense if we haven't done objects and we shouldn't be doing objects yet you're just trying to make a variable so this makes me crazy you know I love me some Java I do love Java and I love Java for more advanced programmers because it doesn't let you do some stupid things that we like to do anyway right dual inheritance now I looked at my kids I think multiple inheritance is a good idea there so there's Java yeah it makes sense doesn't it could we again like all these languages could I take that char to make it work for Java sure I've done it so why Python that's why if you want to teach a beginner to program which of these languages is easiest to translate from the algorithm to code that actually works that's what I love about Python because since I don't care about the language how about we pick one that gets out of the way and gives them success to succeed I want them to feel proud I want them to fail because that's gonna happen but I want them to overcome that failure and so a language that helps us do that that makes me happy makes me happy and I like successful students and here's the other thing they are gonna want to make games fine we can do that somebody's gonna want to write a database sequel lights built-in good now they all want to do - you eyes okay fine TK yeah TK but hey it's built in what do you want to do sure we can do it get it out of your sister you wanna do web apps I taught that tonight I showed them they were still this is their first Python class I showed them bottle because there's no installation I don't want to deal with it's don't like flask on the yeah computer how cool is this isn't this fun so that's really where I am I love to teach beginners because I love the process of learning and I always learn far more than them so thank you for your time I'll be around to answer any questions you guys been awesome a lot of fun [Applause]
Info
Channel: Coding Tech
Views: 1,144,203
Rating: 4.9022775 out of 5
Keywords: programming, software development, coding, learn to code, learn to program
Id: azcrPFhaY9k
Channel Id: undefined
Length: 60min 7sec (3607 seconds)
Published: Fri Oct 26 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.