The differences between compiled and interpreted languages and their advantages and disadvantages

Source: Internet
Author: User
Tags stack trace

There are many kinds of computer programming languages, depending on the degree of closeness to computer hardware and the degree of abstraction can be broadly divided into 3 categories, from top to bottom are:

高级语言(抽象层次更高的便于记忆和表示的英文代码)             |汇编语言(抽象层次较高的对应机器硬件的cpu指令集,英文缩的助记    符号代码)                   

As we all know, the bottom of the computer can only recognize (and execute) 0, 1 sequence of machine code, which means that all the high-level programming language written code, ultimately in some way to be converted into a computer can be recognized by the machine code 0, 1, the computer can be accepted and executed. This way of converting code into machine code can be divided into 2 categories: compiled and interpreted.

Concept:

compiled language : A ready-to-run program that compiles all the good source programs into binary code. Then, you can run the program directly.

interpreted language : Translate a good source program into one sentence, then execute one sentence until the end!

Compiled languages

Compiling means that the program source code is "translated" Into the target code (machine language) before the source program executes, so its target program can be executed independently from its language environment, which is more convenient and efficient to use. However, once the application needs to be modified, the source code must be modified before the new target file (*) is recompiled. OBJ) to execute only the target file without source code, modification is inconvenient. Most programming languages are now compiled. After the compiler translates the source program into a target program, it is persisted in another file, which can run multiple times directly on the computer from the compiler. Most software products are distributed to the user in the form of a target program, which is not only easy to run directly, but also makes it difficult for others to steal the technology C, C + +, Fortran, Visual Foxpro, Pascal, Delphi, Ada are all compiled and implemented.

Interpreted language

In the implementation of the interpreted language, the translator does not produce the target machine code, but produces an easy-to-execute intermediate code, which differs from the machine code, where the interpretation of the intermediate code is supported by the software and cannot be directly used, and the software interpreter usually results in less efficient execution. A program written in an interpreted language is executed by another interpreter that can understand the intermediate code. Unlike the compiler, the task of the interpreter is to interpret the source program's statements as executable machine instructions, without having to translate the source program into the target code before executing it. The advantage of the release program is that when a syntax error occurs in a statement, the programmer's attention can be drawn immediately, and the programmer can correct it during the development of the program. For the interpreted basic language, a specialized interpreter is required to interpret the basic program, and each language is translated only when it is executed. This interpreted language is translated once per execution and thus inefficient. In general, dynamic languages are interpreted, such as Python, Tcl, Perl, Ruby, VBScript, JavaScript, and so on.

Mixed type

Java is very special, Java programs need to be compiled, but not directly compiled called machine language, but rather compiled called bytecode, and then on the Java Virtual machine in the interpretation of the code to execute bytecode. Python also uses a Java-like compilation pattern, which first compiles the Python program into Python bytecode, which is then interpreted by a dedicated Python bytecode interpreter to interpret the execution byte code. (Java Virtual machine Execution of bytecode is equivalent to simulating a CPU, and ruby1.8– before the virtual machine is present – is performed by interpreting it into a syntax tree.) )

Distinguish between compiled languages

1. One of the greatest advantages of a compiled language is its speed of execution. Programs written in C + + will run 30%-70% faster than the same program written in Java.

2. The compiled program consumes less memory than the interpreter program.

3. The downside-the compiler is much more difficult to write than the interpreter.

4, the compiler does not provide much help when debugging the program-how many times in your C code to encounter a "null pointer exception", it takes several hours to identify exactly where the error is in the code.

5. Executable compiled code is much larger than the same explanatory code. For example, A/C + +. exe file is much larger than the same-feature Java. class file.

6, the compiler program is platform-oriented platform-dependent.

7. A compiled program does not support security in code--for example, a compiled program can access any area of memory and can do whatever it wants to do with your PC (most viruses are written in a compiled language)

8, because of the loose security and platform dependence, the compiler language is not suitable for the development of Internet or web-based applications.

Interpreted language

1, interpreted language provides excellent debugging support. A Java programmer can locate and fix a "null pointer exception" In just a few minutes, because the Java runtime not only indicates the nature of the exception, but also gives the exact line number and sequence of function calls (well-known stack trace information) where the exception occurred. This convenience is not available in a compiled language.

2. Another advantage is that the interpreter is easier to implement than the compiler

3. One of the greatest advantages of interpretive language is its platform independence

4, interpreted language can also guarantee a high degree of security-this is an urgent need for Internet applications

5, the size of the intermediate language code is much smaller than the compiled executable code

6, platform independence and strict security are the 2 most important factors that make interpreted language an ideal language for Internet and Web applications.

7. There are some serious shortcomings in interpretive language. An interpreted application consumes more memory and CPU resources. This is because, in order to run a program written in an interpreted language, the relevant interpreter must first run. An interpreter is a complex, intelligent, resource-intensive program that consumes a lot of CPU cycles and memory.

8. Because of the decode-fetch-execute (decoding-crawl-execute) cycles of interpreted applications, they are much slower than compiled programs.

9, the interpreter will do a lot of code optimization, run-time security checks; These additional steps take up more resources and further reduce the speed of the application.

The differences between compiled and interpreted languages and their advantages and disadvantages

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.