What Is Programming?


There are many ways to “talk” to a computer. You’re probably already familiar with some of them. For example, most likely you’ve “surfed” the Web or created a document using Microsoft Word. You may also have used a voicemail system to leave someone at a big corporation a message or even to check your bank account balance. Indeed, it’s hard to do anything in the modern world without communicating with computers.

Programming is a particular way of “talking” with a computer that tells the computer to do something. For example, when you tell your VCR to record a show, you are, of course, programming the VCR.

To take this one step further, each of the examples mentioned earlier— surfing the Web, using a word processor, and navigating an automated phone system—involve using a program created by someone else. The programmer designs the program—the Web browser, word processor, or whatever—so that you can achieve results without having to program anything yourself. The mechanism that you—as opposed to the programmer —use to communicate with the computer is often called a user interface. Many, if not most, computer programs provide a user interface that allows users to interact with the computer nonprogrammatically, often using a visual metaphor such as clicking buttons with a mouse.

This has several interesting implications. First, someone who programs a computer has to think about how a computer interacts with the instructions that make up a computer program. Second, the programmer has to manage how people interact with the program.

The point is that programmers interact with computers in a different— some would say deeper and more significant—way than those who only use programs created by someone else.

To drive this home, think of a game that involves racing cars around a speedway. The programmer has created code that lets the game interact with a computer on which it’s running. The programmer has to also deliver appropriate effects when a user chooses a car, steers and accelerates with a game stick or other device, and so on. Figure 1-1 shows this relationship.

click to expand
Figure 1-1: A program, such as a racing game, interacts with both a computer and users and makes sure that the computer takes the steps requested by the users.

start sidebar
Programmers Can Be Users

In some cases, programmers may be the only people interacting with a particular program. But when they do so, they’re interacting as mere users, not as the programmer who is telling the computer what to do.

end sidebar

start sidebar
Understanding Machine Language, Assembly Language, Operating Systems, and All That

From the viewpoint of this book, you don’t really need to know much about machine language, assembly language, operating systems, and all that stuff. But, in case you’re curious, machine language is the underlying two-position native language of computers. You can think of these two positions as a switch with an on and off (or as a zero and a one). The two positions are also called binary. Machine language manipulates groups of these switches.

Assembly language, also sometimes called assembler, is a somewhat more human-friendly mechanism that can directly communicate with the hardware switches that natively “think” in machine language. Assembly language is specific to a particular processor because its statements correspond to specific machine instructions.

Assembly and machine language are considered low-level languages—they allow direct access to all of the capabilities of the underlying system, but they’re time consuming and tedious to use. In contrast, the programming languages described in the next section are considered high level because they hide the actual low-level details of how something is implemented and combine many low-level commands into single statements.

Operating systems are computer programs—such as Microsoft Windows or Linux—whose principal purposes are to launch other programs, give them resources to run, and keep them out of each other’s way. Operating systems vary greatly in functionality and sophistication. Most also provide a high-level mechanism for programmers to utilize underlying system capabilities to perform tasks such accessing files on a disk.

end sidebar

Exploring Programming Languages

Programming languages are the way programmers communicate with computers. As you’ll see in this book, in some sense computers aren’t inherently very bright. The programmer generally supplies the smarts— which can range from nonexistent to vast.

In the words of Tolstoy, “Happy families are all alike.” Similarly, all modern high-level programming languages are really pretty much alike.

To say that all programming languages are pretty much alike might evoke gasps of horror from adherents of one language or another—and, truthfully, it’s an exaggeration because some important differences exist between languages. However, it’s not a bad generalization.

Like human languages, computer programming languages use specific words, often called keywords, to mean specific things. Keywords are typically human-language-like so that their meanings can be intuitive. For example, the keyword if generally tells the computer to do one thing or another thing depending on how a condition is evaluated. This is comparable to the English sentence “If it’s after 3 P.M., pick up the baby.”

In other words, the If in the sentence tells someone to check the time and, if it meets the condition (it’s after 3 P.M.), to do something (pick up the baby).

In human languages, rules of grammar and syntax are used to put words together into phrases and sentences, such as the example sentence “If it’s after 3 P.M., pick up the baby.” Then sentences are combined to tell a story, give directions, or provide a million other purposes.

Computer languages work the same way. In other words, you put keywords and other elements together using rules of syntax to create statements. (You can think of a statement as a sentence in a computer program.)

These statements combine to create computer programs.

The syntax of a programming language is the basic scaffolding you use to create programs and applications with that language. Understanding the syntax means understanding how a language works—and knowing what the language can (and can’t) do.

If you learn a foreign language, then you can communicate with natives who speak that language. Similarly, if you learn the language of computers, you can “speak” with a computer. Just as it helps to learn a foreign language by thinking the way native speakers do, it helps to learn to think like a computer if you want to learn a computer’s language. (So, really, this book is about computer psychology.)

However, before a computer can run a computer program that’s written in a human-like language, the program needs to be translated into code that the machine understands. Programmers accomplish this using special programs called compilers and interpreters.

start sidebar
Understanding Compilers, Interpreters, and Why Not to Worry

A compiler translates a high-level program into machine code and creates an executable program that can be processed by the machine. In contrast, an interpreter translates program statements in code that can be processed by the computer on the fly, a kind of “pay-as-you-go” scenario.

Although professional programmers may have to worry quite a bit about the nature of the compiler or interpreter they’re working with, often these programs are built into the development environment used to create the program.

In the case of the programs you’ll write using this book, you don’t have to worry about these things at all because JavaScript—the language used in this book—has an interpreter built into every modern Web browser.

end sidebar




Learn How to Program Using Any Web Browser
Learn How to Program Using Any Web Browser
ISBN: 1590591135
EAN: 2147483647
Year: 2006
Pages: 115
Authors: Harold Davis

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