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.

Figuring Out Programming 23<br />

certain types of <strong>programming</strong> languages known as scripting languages. (Find<br />

out more about scripting languages in Book I, Chapter 3.)<br />

Book I<br />

Chapter 1<br />

Combining a compiler with an interpreter<br />

to create p-code<br />

Creating separate executable files <strong>for</strong> each processor can get clumsy and giving<br />

away your source code with an interpreter may be unreasonable, so a third<br />

approach is to compile your program into an intermediate <strong>for</strong>mat called bytecode<br />

or pseudocode (often abbreviated as p-code). Unlike compiling source<br />

code directly into machine language, you compile your program into a p-code<br />

file instead.<br />

Getting Started<br />

Programming a<br />

Computer<br />

You can take this p-code file and copy it on any computer. To run a p-code<br />

file, you need a special p-code interpreter, or a virtual machine. The virtual<br />

machine acts like an interpreter and runs the instructions compiled into the<br />

p-code file.<br />

✦ The advantage of p-code is that you can distribute a single p-code version<br />

of your program, which can run on multiple computers.<br />

✦ P-code has a couple disadvantages:<br />

• P-code programs don’t run as fast as programs compiled into<br />

machine language.<br />

• If a computer doesn’t have the right virtual machine installed, it can’t<br />

run your program.<br />

The most popular <strong>programming</strong> language that uses p-code is Java. After you<br />

write a Java program, you can compile it into a p-code file, which can run on<br />

any computer that has a copy of the Java virtual machine (VM), such as<br />

Windows, Mac OS X, and Linux.<br />

The theory behind p-code is that you write a program once and you can run<br />

it anywhere. The reality is that every operating system has its quirks, so it’s<br />

more common to write a program and be <strong>for</strong>ced to test it on multiple operating<br />

systems. More often than not, a p-code program runs perfectly fine on one<br />

operating system (like Windows) but suffers mysterious problems when running<br />

on another operating system (such as Linux). Languages, such as Java,<br />

are getting better at letting you run the same program on multiple operating<br />

systems without major modifications, but be careful because p-code doesn’t<br />

always work as well as you might think.<br />

Taking the time to understand<br />

Programming is a skill that anyone can acquire. Like any skill, the best way<br />

to understand is to take the time to experiment, make mistakes, and learn<br />

from your failures. Some programmers prefer to spend their time mastering

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

Saved successfully!

Ooh no, something went wrong!