Let's step back and think about what we are doing. When we write code, we make it visually appealing, and nice to look so it is easy to read. Easy to read for who? The computer? No. The only thing the computer needs is for the ; and { to be in the right place and it doesn't care what it looks like. It could all be mashed up into one line and it would run just fine. We make the code look nice so we can make sense of it. It is important to understand how the computer reads through and processes your code.
I like to think of it like reading a book. We spend our time writing this book, and then when we want the program to run, we hand the text over to the compiler, and it mashes it all together for the computer to process, and it just goes through and reads it. Pretty straight forward. But how does it go about reading it? Does it read it left to right, top to bottom? Is it right to left bottom to top? Well the answer to that is that the computer reads and process code in the order you tell it to. So you can think of computer programming as handing the computer a choose your own adventure book, and it going through to different places in the book based on where that page takes it, not necessarily sequentially. Think about that long and hard. It is like we are writing our own choose your own adventure book where our book isn't read sequentially, but depending on where we tell it to go.
So the whole idea behind computer programming is that you understand where the control is in your program, and then you send it off to do whatever you need it to do. For our basic purposes, control can only do one thing at a time. It goes where you send it and does what you want it to do. You control where the control goes, and that is how you make software work.
So how long does it take for the computer to read through our program? In the example we have been working with, it is processed extremely fast. Like fractions of a second. So in order to better understand how control works, there has to be a way to slow the computer down so we can see what it is doing, right? Right. It is called debugging. We can put breakpoints in our code that tells the ultra-fast computer to slow down and wait for us lesser humans.
We will go over that in an upcoming post, but first, more on methods ! Stay tuned!
No comments:
Post a Comment