20 Figuring Out Programming Figure 1-2 shows a simple editor used to write a BASIC program that creates a lunar lander video game. Without an editor, you can’t write a program. With an editor, you can write a program, and with a really good editor, you can write a program quickly and easily. Professional programmers often get passionate (to the point of fanaticism) about their favorite editors. The quickest way to get into an argument with programmers is to either insult their favorite programming language or insult their favorite editor. If you insult a programmer’s mother, the programmer will probably just shrug and not care one bit. A file full of program commands is called the program’s source code. Think of a program’s source code as the recipe that makes the program work. If someone can steal or copy your source code, he’s effectively stolen your program. That’s why companies like Microsoft jealously guard the source code to all their programs, such as Microsoft Windows or Excel. Figure 1-2: An editor lets you write and edit the source code of a program.
Figuring Out Programming 21 Converting source code with an assembler or compiler An editor lets you type and save program commands (source code) in a file. Unless you’ve written a program completely in machine language, your source code might as well have been written in Swahili because processors don’t understand any language other than machine language. So to convert your source code into machine language commands, you have to use an assembler (if you wrote your program commands in assembly language) or a compiler (if you wrote your program commands in the C language or a high-level language, like BASIC). Book I Chapter 1 Getting Started Programming a Computer After converting your source code into equivalent machine language commands, an assembler or compiler saves these machine language commands in a separate file, often called an executable file, or just an EXE file. When you buy a program, such as a video game or an antivirus program, you’re really buying an executable file. Without an assembler or a compiler, you can’t create your program. Compilers translate source code into machine language, which is the native language of a specific processor. But what if you want your program to run on different processors? To do this, you have to compile your program into machine language for each different processor. You wind up with one executable file for each processor, such as an executable file for an Intel Core Duo 2 processor and a separate executable file for a PowerPC processor. Many Macintosh programs advertise themselves as a Universal Binary — the program actually consists of two executable files smashed into a single file: ✦ One executable file contains machine language code for the PowerPC processor (used in older Macintosh computers). ✦ The second executable file contains machine language code for the Intel processor (used in new Macintosh computers). Most compilers work only on one specific operating system and processor. So a Windows compiler can only create programs that run under the Windows operating system. Likewise, a Linux compiler can only create programs that run under the Linux operating system. If you write a program that runs under Windows, you can re-compile it to run under Linux. Unfortunately, you may have to modify your program slightly (or a lot) to make it run under Linux.