15.04.2018 Views

programming-for-dummies

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

92<br />

Finding an Interpreter<br />

The advantages of interpreted languages<br />

A program run by an interpreter is almost<br />

always slower than the same program compiled<br />

into machine language, so why not compile<br />

every language rather than run them under<br />

an interpreter?<br />

One of the reasons is that creating a compiler <strong>for</strong><br />

multiple operating systems is much more difficult<br />

than creating an interpreter <strong>for</strong> multiple<br />

operating systems. To create a compiler, you<br />

need to know how to translate a <strong>programming</strong><br />

language into machine code, but because operating<br />

systems can run under different processors<br />

(such as the PowerPC or Intel processors),<br />

you have to translate language commands into<br />

completely different machine language commands.<br />

Creating a compiler that works correctly<br />

<strong>for</strong> one processor is hard enough, but creating<br />

that same compiler to work under multiple<br />

processors identically and error-free is much<br />

more difficult.<br />

Compiling a program into machine language is<br />

great when you want to distribute a program to<br />

others. However, languages like Ruby or Perl<br />

are often used to create short programs that run<br />

on a Web server. Using an interpreter may run a<br />

program slower, but you can write a program<br />

and run it right away without compiling it first.<br />

Also, by running the source code directly, interpreters<br />

let you see the source code of each program<br />

that’s running, so you can edit that source<br />

code and run it right away to see how your<br />

changes affect the program. You can still do this<br />

with a compiler, but having to compile a program<br />

and then store a separate executable version of<br />

that program is a minor annoyance that you can<br />

avoid completely just by using an interpreter.<br />

Compilers are great <strong>for</strong> distributing<br />

programs.<br />

Interpreters are much better <strong>for</strong> writing and<br />

running shorter programs when you don’t<br />

care whether anyone can see or copy the<br />

source code.<br />

Although JavaScript interpreters can be found in any Web browser, you may<br />

have to download and install interpreters <strong>for</strong> other <strong>programming</strong> languages.<br />

Some popular <strong>programming</strong> languages <strong>for</strong> running programs on Web servers<br />

(those computers responsible <strong>for</strong> displaying and retrieving in<strong>for</strong>mation from<br />

Web pages, such as shopping data) include<br />

✦ PHP (www.php.net)<br />

✦ Perl (www.perl.com)<br />

✦ Python (www.python.org)<br />

✦ Ruby (www.ruby-lang.org)<br />

The preceding four languages not only have free interpreters that you can<br />

copy, but their interpreters also run on different operating systems. That<br />

means a Ruby or Perl program written on a Windows computer should run<br />

identically if copied and run on a Linux or Mac OS X computer.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!