Meet Ruby / Compiled versus Interpreted
Subtitles of the Movie
In this video we're going to look at the difference between compiled and interpreted languages and we're going to look at some examples. So, first let's look at an interpreted language, and that's Ruby, so we're looking at Ruby here. I'm going to open up my text editor, and look at my little program here. Let me fix that right away. So when I go to execute this I can do it from the command line. Now if you're in Windows, you're going to have to open up your command line a little bit differently, this is on a Mac. I'm already in my directory where this file is stored at, and to execute it I'm simply going to type in Ruby and the file name, and it starts running right there, enter in my name, and it says Hello, Allen, your name has three letters. Now if I want to make a change here, let's go in there and um, let's do this. Save it out, jump back to my editor, run it again, and you can see there's the changes, and I didn't have to do anything other to make those changes and save it out to the system, and so remember when we're using an interpreter it's simply going line by line. It's looking through here going boom, boom, boom, boom, and executing whatever is on that line. Now let's take a look at a C program and this video series is about Ruby so don't get caught up in the language or anything on what it looks like, C can be very overwhelming. This example does part of what that other one does; it gets, it has the person enter their name and then it prints out hello and that person's name. So it has that first bit of functionality, it doesn't have that last bit about how many letters are in the name. Although we could easily add that if we wanted to. So, in order to actually run this, I can't just type in the name like I did here. I actually have to compile it. I have to use a compiler. Now on, on, this is going to vary on platforms, how you do this, and you aren't going to be able to do this part on Windows like this. If you have some of the Windows development tools installed that's a whole different process to do this. You have to use Visual C, it's a very gooey type thing, and there is command line components to it and um, it's way too complicated to go here. There is GCC available for Windows if you wanted to go that route, but we're not worried about that here, we're worried about Ruby here. And in other videos we'll actually get into how to install Ruby and all that, but for the moment we're just getting an overview here of these languages and the differences. So to compile this we're going to use GCC, which is just the name of the compiler, and we'll go ahead and type that in here. And really that's just what I wanted to cover is, is how you would use something like this. So I give it the name of the file and then I'll give it an output file name, and then it compiles it. Now the file actually exists, and if I type in, I'm going to execute it here and enter my name, and there we go. Now if I want to make a change here, say I want to get rid of this; if we look here there's like an extra space in here after I type in this and before it kicks back the hello, so let's go ahead and get rid of that. It's on that line there. Save it out, my process says to do that, now I can run it again and you can see now it has the behavior. So yeah, it's just a little extra step but this is a very simple little program. If it was a very complex program, that can take some time to do and you're jumping back and forth there, and it's not going to respond immediately. The other interesting thing is that if you have an interpretive program where it is accessing different files, in other words you have a system where one file is being interpreted at the moment and it accesses other files, you can go ahead and change that other file, and those changes are immediate. You don't have to recompile that code to have it go ahead run. In a compiled language when you change another file, you have to recompile, at least for sure dot project, and if it changes any kind of reference stuff then you have to recompile the main, too, a lot of times. So that's kind of what you're looking at there for the process of, of interpretive, something like Ruby, this interpreted programming versus compiled. Now let's take a look. There is no, if I type in here, and let's look at all the hello's, there are no other hello's for this Ruby. This is it; that's the only file. Whereas the C, we have our source code and we have our output binary file. And you should realize that in an earlier video I talked about linking and understand that the GCC compiler on Mac OS X here automatically links at the end of its compile process, so I don't have to do that step in here. I could put flags in here and manually do it, but it does it for me, thankfully. Now one last thing, I want to take a look at this, at that code here, so let's go in and actually take a look. Here is our machine code, so I'm looking at Hello Input, that's the program we ran, so this is binary code, here's that ones and zeros I've shown in other videos, earlier videos, there's a definite structure to this file. Our actual program starts right in here and if we scroll down a little bit you'll see here is our text for Enter Your Name, and then the Hello, and it's stored at the end down here. And there's some other information in here, but that's pretty much it. That's our program in the binary code of this particular computer and this tells the computer what to do at that lower level.
Tutorial Information
| Course: | Programming With Ruby |
| Author: | Al Anderson |
| SKU: | 33788 |
| ISBN: | 1-934743-01-1 |
| Release Date: | 2007-08-21 |
| Duration: | 8.5 hrs / 113 lessons |
| Work Files: |
Yes |
| Captions: | For Online University members only |
| Compatibility: |
Vista/XP/2000, OS X, Linux QuickTime 7, Flash 8 |
VTC Sign up & Benefits
- Unlimited Access
- 81,350 Video Tutorials (20,800 free)
- Video Available as Flash or QuickTime
- Over 782 Courses
- $30 for One Month Access
- Multi-User Discounts Available
United States 