***Check out our Pong Video and Code!***
***Learn to program and prototype with Arduino now! Join our membership.***
***Get the code, transcript, challenges, etc for this lesson on our website***
***We designed this circuit board for beginners!***
Kit-On-A-Shield:
FOLLOW US ELSEWHERE
---------------------------------------------------
Facebook:
Twitter:
Website:
________________________________
Now, it might come as a shocker to some folks but the more you learn how to program, the more code you end up reading than actually writing. I mean, you could be reading code in a library that you want to use, or you could be reading a teammate’s code, or reading code that you wrote that you totally forgot about, whatever the case, reading code is a fundamental part of being a programmer. The better you can read and digest code, the more capable you’ll be to be able to talk about that code with someone else or modify and use that code for your own purposes. In this lesson, we’re gonna cover strategies for helping you read code that you may not have written. Stay tuned. Well before we dive in, I’d really appreciate if you could take a moment and click that subscribe button. It doesn’t cost you but a click but it really helps us grow our YouTube channel and bring you great content like this. So let’s cut straight to the chase. Reading other people’s code can be hard, even if it’s well written code. I mean, it’s pretty tough just to code something yourself. Trying to figure out what other people wrote is sometimes even more daunting. Worse yet is when you’re brand new to programming, then it feels like you’re reading ancient Sanskrit. So let’s talk about a couple strategies to hopefully make this easier for you. So let’s start with some actual code. This code right here is from our Pong video game project. If you haven’t seen that video, you should check it out. It’s pretty cool. This code that you see here was written by Steve, one of the technical writers and contributors at Programming Electronics Academy. He did this project just for fun and like I said, it’s pretty cool. All in all, we’re looking at just over 400 lines of code. That’s everything, spaces and comments, but you know, it feels like a lot and if I’m being honest big pieces of code always intimidate me. I think to myself like, “Man, this is too complex “for some guy like me to understand,“ because I am no wiz. You know what I’m saying? So the first thing I try to do when reading other people’s code is to set reasonable expectations. I should expect that it will be hard to read and understand code and that it’s gonna take me a bit of time. If I think in my head that I’ll just be able to pop in and understand some code from top to bottom in no time flat, I am kidding myself and I’m really just setting myself up to be frustrated. I mean, maybe some folks are wiz kids, they can read code super fast, understand it all. That is just not me. So I just try to keep it real. The other expectation I have is that there are going to be things that I should know that I will forget. For example, I should know how to write code for a rotary encoder. I’ve written code for rotary encoders. I’ve studied code for rotary encoders. But in many cases my memory is like a broken fishnet. It seems like everything I learn tries to escape out the back door. So I could sit around and kind of cry about that, or I just recognize that, “Hey, this is a feature of my brain, I just deal with it.“ So anytime that I’m looking at some code, if I forget something that I know I should know I don’t beat myself up about it. I just look it up. Hey, that’s life. So what’s the moral of the story here? This is it. You are setting yourself up for disappointment if you think you’ll be able to understand a complex piece of code without exerting some effort and trying to understand it. So when you start reading some code and you feel confused, hey, that’s just a normal part of reading code. It’s nothing to get worked up about. So once I remind myself of some reasonable expectations, the next thing I do is try and anticipate what I might find in the code. So most software developers will spend time thinking about the code they’re going to write before they actually write the code. Thinking and planning what you’re going to do is an important part of software development.
CONTINUED...
***About Us:***
This Arduino lesson was created by Programming Electronics Academy. We are an online education company who seeks to help people learn about electronics and programming through the ubiquitous Arduino development board.
***We have no affiliation whatsoever with Arduino LLC, other than we think they are cool.***