What is the difference between a weak type, a strong type, a dynamic type, or a static type language?

Source: Internet
Author: User
Tags ocaml

Amalgamation
Links: https://www.zhihu.com/question/19918532/answer/21647195
Source: Know
Copyright belongs to the author. Commercial reprint please contact the author for authorization, non-commercial reprint please specify the source.

1. Define some basic concepts first
Program Errors
    • trapped errors. Causes the program to terminate execution, such as an array of out-of-bounds access in addition to 0,java
    • untrapped errors. Continue execution after an error, but any behavior may occur. such as a buffer overflow in C, jump to the wrong address
Forbidden Behaviours

When designing a language, you can define a set of forbidden behaviors. It must include all untrapped errors, but may contain trapped errors.


Well behaved, ill behaved
    • Well behaved: If forbidden behaviors is not possible for program execution, it is the well behaved.
    • Ill behaved: otherwise ill behaved ...

2. With the above concept, then discuss the strong, weak type, static, dynamic type

strong and weak types
    • strongly typed strongly typed: If all programs in a language are well behaved--that is not possible forbidden behaviors, then the language is strongly typed.
    • weak type weakly typed: otherwise weakly typed. For example, the C language buffer overflow, belongs to the trapped errors, namely belongs to forbidden behaviors. So C is a weak type
Earlier people also said that weakly typed languages, type checking is less stringent, such as bias tolerance implicit type conversion. For example, the C language int can be double. The result is that it is easy to produce forbidden behaviours, so it is a weak type

dynamic, static type
    • static type statically: If the ill behaved program is rejected at compile time, it is statically typed;
    • dynamic Type dynamiclly: If ill behaviors is rejected at run time, it is dynamiclly typed.
3. Pitfalls
People think C language to write int a, int b and so on, Python does not write (can directly write a, b), so C is static, Python is dynamic. This understanding is not accurate enough. For example, OCaml is static type, but it can not be explicitly written out.
OCaml is static implicit type

static types can be divided into two kinds:
    • If the type is part of the language syntax, it is explicitly typed explicit type;
    • If the type is deduced by compile-time, it is implicity typed implicit type , such as ML and Haskell

4. Here are some examples
No type: assembly
Weakly-typed, Static-type: C + +
Weak type, dynamic type check: perl/php
Strongly typed, static type checking: java/c#
Strongly typed, dynamic type checking: Python, Scheme
Static an explicitType: JAVA/C
Static implicit type: Ocaml, Haskell

What is the difference between a weak type, a strong type, a dynamic type, or a static type 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.