What Is Programming?

[ LiB ]

To ease you in, I'll first describe what a computer program actually is. Simply put, a computer program is a file that contains a list of instructions for the computer to follow. Now that I've thrown that general statement at you, let's talk about generic system architecture. This will help you better understand the concepts that will be explored throughout this book.

When you click on a button, or select an option from a menu, or give your computer any other task to carry out, your computer fetches the instructions from its RAM. RAM stands for Random Access Memory . This is where all the running (and sometimes dormant ) programs are stored while the computer is on. RAM is also the place where your scripts will be interpreted and where the computer will fetch the code.

Once the computer finds the instructions for carrying out the task you've ordered, the CPU executes the task. The CPU, or Central Processing Unit , is the brain of the computer.

NOTE

NOTE

Hertz is a measure of cycles per sec ond. Computers nowadays are mea sured in gigahertz, which clock in at a billion cycles per second. Older computers are measured in mega hertz, which clock in at a million cycles per second.

The speed at which the CPU can fetch instructions is measured in cycles per second, or hertz. Check out Figure 2.1 for an easy-to-swallow visual.

Figure 2.1. Simplified generic system architecture

graphic/02fig01.gif


As you get more experienced , you will learn how to optimize your code so that your program can run much faster overall. But there's no need to get ahead of ourselves . As I said before, a computer program is simply a file that contains a list of instructions for the computer to follow.

What instructions does the computer understand? A computer language is nothing like a spoken language. It's more like an instruction set that can and should be written out in a certain way. This certain way is referred to as the language's syntax . The computer will complain if it doesn't understand the instruction that you give itif you don't use the correct syntax.

A few examples of computer languages include C, C++, BASIC, Assembly Language, and ActionScript. These languages are all different, but once you understand the fundamental programming concepts behind them, it won't be difficult to understand them all. Most of the learning curve comes while learning your first computer language. Our language in this book, of course, is ActionScript.

Computer languages were designed to be understood by humans, not by machines. In order for the machines to understand the code that humans write with these languages, special pieces of software called compilers and interpreters are designed to "explain" what these languages are saying in a form that a computer can understand. This being so, some languages are compiled and others are interpreted. What this means is that compiled languages are compiled through compilers and interpreted languages become understandable to the CPU through interpreters.

NOTE

NOTE

Compiled languages are translated into machine code, which the CPU directly understands.This is why a compiled program is said to run "on the CPU." Some examples of compiled programs include Macromedia Flash MX and Adobe Photoshop; you can run these programs by simply double-clicking on their icons. An interpreted language it not designed to run directly on the CPU, but rather "inside" another software program, called an interpreter. An example of such a language would be ActionScript's cousin, JavaScript. A Web browser takes this code and performs the actions the scripts specifies, thus performing an interpreted task. ActionScript is always interpreted because it needs Flash to be executed.

Compiled languages have some advantages over interpreted languages, some of which are vital when it comes to games . One of these advantages is speed. As compiled languages are converted to the computer's native machine code at an earlier stage, there is no translating necessary when the program is being run. Interpreted languages like ActionScript are generally slower because they must be translated while the script is being executed. This overhead causes a significant slowdown .

NOTE

NOTE

Internet Explorer is an excellent example of a compiled stand-alone executable program. It was built with another language, such as C++.

One thing you must know about interpreters is that when you give your code to someone else to run, he or she must also have that darn interpreter. A nice thing about Flash is that millions of Internet users on cross-platforms have the Flash Player installed. The Flash Player not only plays Flash movies but also interprets our wonderful ActionScript language. But Macromedia didn't stop there. Their Flash Player can actually compile the Flash movie into a stand-alone projector file. This will allow anyone without a Flash Player to view the movie. As virtually everyone with a computer has the Flash Player installed, the only time I would use the projector is an instance in which a user doesn't have an updated player.

Now that you have a basic idea of what programming is, let's move on and expand your knowledge of what ActionScripts are. ActionScripts fall into the category of computer programs but their execution process is completely different from a stand-alone compiled program. As we move through the chapter and pick up these essential concepts, I will get more ActionScript-specific with my text. Before you know it, you will be writing and showing off your own ActionScript games.

[ LiB ]


Game Development with ActionScript
Game Development with ActionScript
ISBN: 1592001106
EAN: 2147483647
Year: 2004
Pages: 162
Authors: Lewis Moronta

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net