5: Interpreted Or Compiled?
Take Up Code - Podcast autorstwa Take Up Code: build your own computer games, apps, and robotics with podcasts and live classes
Kategorie:
Learning how to program effectively will eventually require that you learn more than just one language. You already know that there are different types of languages and different levels. There’s another fundamental difference between some languages such as between C++ and C#. Some languages are interpreted and some are compiled. And some like C# get compiled twice with some aspects of being interpreted too. Knowing how your code behaves will allow you to select the best tool for the job. This episode builds on the turn left or right, jump, and take steps game by comparing different approaches that you could take and then showing how one approach leads to an interpreted solution while the other leads to a compiled solution. It seems like compiling is the better option until you learn how flexible the interpreted solution can be. So are languages interpreted or compiled? They can be either and sometimes evolve from one to the other. Knowing how your programming language currently behaves and what to expect from it in the future are critical to building a successful application. Listen to the full episode or read the full transcript below. Transcript Let’s start by going back to the game described in episode 4. You’re playing a game with a friend and you can give your friend 4 simple instructions to turn left or right, jump, and take from 0 to 5 steps. Your friend has a starting point and will follow your instructions exactly to reach a destination. The one catch here is that your friend wants these instructions in the form of numbers where 0 means turn left, 1 means to turn right, 2 means to jump, and 3 means to take steps. The number of steps to take follows the 3. So a 3 followed by another 3 is a valid sequence and means to take 3 steps. There wouldn’t be much of a challenge to this game if you could just follow behind your friend and figure out what direction to go as needed. You might as well just walk directly to the destination. So to make things more interesting, you’ll need to plan the instructions you can give to your friend ahead of time because once the game begins, you can’t change them. This series of instructions becomes your source code. Now you want to work with your source code in terms you can understand. But your friend wants the instructions as a series of numbers. You have a lot of planning to do and working with numbers directly would lead to too many mistakes. So you’re going to need something that will turn your source code into the numbers that your friend expects. One way to do this would be to write your source code in your own terms and then follow your friend and translate each instruction to numbers as needed. This will meet the rules of the game because you’re not changing your instructions, just translating them as needed. In other words, you’re interpreting your instructions. You’ll be a bit slow to navigate because your friend will need to pause after each instruction while you translate the next source code instruction. Another way would be for you to translate all of your instructions once before the game begins. You’ll be more prepared this time because you compiled everything. The benefit is that you can navigate faster because you’ll have each instruction already translated and ready as soon as it’s needed. You won’t have your source code anymore with you during the race. Just your series of numbers that you compiled. If this was a race between two teams that have both written their source code before the race begins and one team took the interpreted approach while another took a compiled approach but waited until the race begins to start compiling, then they would probably end up at the destination at the same time. But that’s only because the compiling was done as part of the race. That’s not the way things work. When you compile your source code, you have the opportunity to do this work once