10.1. What Is a Script?

In Chapters 6 and 7 you learned about the C and Objective-C programming languages, which form the basis of much of the development taking place on Mac OS X today. These languages are compiled languages, which means they have to be converted from source code into object code, which the CPU understands, by a program called a compiler. When you write in compiled languages, you have to build your program before you can run it.

A script is a program written in an interpreted language. An interpreted language is one that does not get compiled before it is executed. Instead, the source code of the program is read directly, one line at a time, by a program called an interpreter. An interpreter is similar to a compiler, in the sense that its job is to convert source code into instructions that the computer can execute, but there is an important difference: A compiler performs the entire conversion before the program is run, generating an executable in a form that can be directly understood by the CPU. An interpreter performs the conversion on-the-fly, reading a line of code at a time, interpreting it, and carrying out the corresponding operations before reading the next line.

Another way of looking at it is that a compiled program runs directly on the CPU, whereas a script runs inside an interpreter, which runs on the CPU. This level of indirection means that scripts generally run quite a bit slower than compiled languages, but when this performance penalty is not ...

Get Beginning Mac OS® X Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.