ASK SENSEI
.net
AN E-LEARNING TOOL BUILT JUST FOR YOU
Whiteboard
SAT® Vocab Practice
Tutorial
About
Contact
Math Studio
Whiteboard
SAT® Vocab Practice
Tutorial
About
Contact
Math Studio
Log in
Scripting vs. Compiled Programming Languages
• Computer Science •
Scripting programming language
Compiled programming language
Programming languages can be broadly classified into two categories: scripting languages and compiled languages. The main difference between these two categories lies in the way the code is executed by the computer.  **Compiled Programming Languages** A compiled language is a programming language that is translated into machine code before it is executed by the computer. The compilation process involves the following steps: 1. **Preprocessing**: The preprocessor reads the source code and expands any macros or includes. 2. **Compilation**: The compiler translates the preprocessed code into assembly code. 3. **Assembly**: The assembler translates the assembly code into machine code. 4. **Linking**: The linker resolves any external references and creates an executable file. The resulting executable file can be run directly by the computer without the need for any additional software. **Example: C** C is a classic example of a compiled language. When you write a C program, you need to compile it using a compiler like `gcc` before you can run it. The compilation process involves the following steps: ```c // hello.c #include <stdio.h> int main() { printf("Hello, World!\n"); return 0; } ``` To compile and run this program, you would use the following commands: ```bash $ gcc hello.c -o hello $ ./hello Hello, World! ``` As you can see, the compilation process creates an executable file called `hello` that can be run directly by the computer. **Scripting Programming Languages** A scripting language, on the other hand, is a programming language that is interpreted or executed line-by-line by an interpreter at runtime. The interpreter reads the source code and executes it directly, without the need for compilation. **Example: Python** Python is a popular scripting language. When you write a Python program, you can run it directly using the Python interpreter without the need for compilation. ```python # hello.py print("Hello, World!") ``` To run this program, you would use the following command: ```bash $ python hello.py Hello, World! ``` As you can see, the Python interpreter reads the source code and executes it directly, without the need for compilation. **Key differences** Here are the key differences between scripting and compiled programming languages: * **Compilation**: Compiled languages require a separate compilation step before the code can be executed, while scripting languages are executed directly by the interpreter. * **Speed**: Compiled languages are generally faster than scripting languages because the compiled code can be executed directly by the computer, while scripting languages require the interpreter to read and execute the code line-by-line. * **Portability**: Scripting languages are often more portable than compiled languages because they can be run on any platform that has an interpreter, while compiled languages require a specific compiler and runtime environment for each platform. * **Development cycle**: Scripting languages often have a faster development cycle than compiled languages because changes to the code can be made and tested quickly without the need for recompilation. **Comparison of C and Python** Here's a comparison of C and Python in terms of their characteristics as compiled and scripting languages: | Characteristic | C (Compiled) | Python (Scripting) | | --- | --- | --- | | Compilation | Required | Not required | | Speed | Faster | Slower | | Portability | Less portable | More portable | | Development cycle | Slower | Faster | | Syntax | More verbose | Less verbose | | Type system | Statically typed | Dynamically typed | In summary, C is a compiled language that requires a separate compilation step before the code can be executed, while Python is a scripting language that is executed directly by the interpreter. While C is generally faster and more efficient than Python, Python is often more portable and easier to develop with due to its simpler syntax and dynamic typing.