What are dynamic languages and static languages? The difference between static language dynamic language

Source: Internet
Author: User

Defined
Usually we call dynamic language, static language refers to dynamic type language (dynamically Typed Language) and static type language statically Typed Language).
There is also a dynamic programming Language (Dynamics programming language), a static programming language.

Dynamic type language: The language that examines the type of data during run time. Programming in such a language does not give the variable a type, but a data type when it is attached. For example, Python and Ruby are typical dynamic type languages. Many scripting languages vbscrīpt,javascrīpt are also such languages. Look at the following JAVASCRĪPT code:

function Add (A, b) {
return a+b;
}
Add (+);
Add (' 1 ', 2);



Static type language: The opposite of a static type language is the check type at compile time before running. When writing code, there is no declaration that a variable must specify a type. such as: Java,c#,c,c++ and so on.
public int Add (int a,int b) {
return a+b;
}
In fact, compare the code, you will soon find that, in fact, the distinction between dynamic static type language from the syntax is enough, the language grammar format can confirm the dynamic static type.

The dynamic programming Language (dynamically programming language) refers to the structure of the data type that can be changed during the program's operation, the function of the object, and the variable can be deleted. For example: JAVASCRĪPT is such a language, Ruby, Python also belongs to this kind of language. And C++,java does not belong to such language. See JAVASCRĪPT Code:

function person (name) {
This.name=name;
}
Person.prototype.getname=function () {
return this.name;
}
var person=new person ("Okok");
Alert (Person.getname ());
Person.getname=function () {return "Nono"};
Alert (Person.getname ());



Of course, static programming language is the non-changing structure of the runtime.

Some people on the web say that type checking and changing structures are two points of difference between static and dynamic languages. The basic concept should be that these, I personally understand, not necessarily completely correct. Personal feeling there is no need to clear the categories, grasp the advantages, characteristics of good. This topic is not what I can say at all. Summarize and think about it.

There are three nouns that are easy to confuse:

    1. Dynamic programming Language (dynamically language or dynamic programming language)
    2. Dynamically Typed Language (dynamic type language)
    3. Statically Typed Language (static type language)

The dynamic language and static language mentioned by Fantasysoft in his article actually refer to dynamic type language and static type language.

Dynamic language, to be precise, means that a program can change its structure at run time: New functions can be introduced, existing functions can be deleted, and so on, structural changes. For example, the well-known ECMAScript (JavaScript) is a dynamic language. In addition, such as Ruby, Python and so on are also dynamic languages, and C, C + + and other languages are not dynamic language.

The so-called dynamic type language, meaning that the type of check is done at runtime, such as the following code is not legal to be judged at runtime (note is the runtime type judgment):

Defsum (A, B):
Return a + b

The type of static type of language is judged before running (such as the compilation phase), such as C # is a static type language, static type language in order to achieve polymorphism will take some type of authentication means, such as inheritance, interface, and dynamic type language is not required, so the general dynamic language will be used in the dynamics typing , which often appears in the scripting language. (Idior don't know if this can answer your question about dynamic language polymorphism ^_^)

Here I need to make it clear that the dynamic type language is not completely irrelevant to the type of the language, and do not link them together!

The main advantage of the static type language is that its structure is very normative, easy to debug, convenient type security, the disadvantage is that it needs to write more type-related code, resulting in not easy to read, unclear. The advantage of dynamic type language is that it is convenient to read, do not need to write a lot of type related code, the disadvantage is that it is inconvenient to debug, the naming is not standard will cause the reading does not understand, is not conducive to understanding and so on. By the way, there is now a tendency to combine dynamic and static types in a language so that it can be useful when necessary, and Boo is a good example of experimentation. ^_^

Finally, say Boo,boo is a static type language, although the dynamic typing can be simulated with the duck typing, but duck does not support all types of operation overrides, so even if the duck typing is fully used, dynamic typing cannot be reached. As Fantasysoft, type inference is not an attribute of a dynamic type language, so supporting type inference does not mean that the language is dynamically typed.

Again specially for Ninputer this VB fans say vb.net ^_^, VB. NET is dynamically typed language.

What are dynamic languages and static languages? The difference between static language dynamic language

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.