Typing - GradedJestRisk/lexicon GitHub Wiki

Table of Contents

Typing: Static/Dynamic - Strong/Weak

Fundamentals

Come from here Static and dynamic typing, and strong and weak typing, are two totally different concepts, which, unfortunately, are very often confused. It is erroneous to say that a language that is static or dynamic typed cannot be strong or weak typed.

Glossary

PL: programming language.

Variable:

  • (type) declaration
  • (value) definition (= initialized, given value)
  • use (in an expression)

Declare (variable)

Static

Variables need NOT be defined before use
They must be explicitly declared.
Variables maybe be initialized anywhere, as long as it occurs before variables usage.

Dynamic

Variables must be defined before use.
declaration is meaningless, because type is linked to a particular definition.

Type checking : when ?

Type checking time:

  • static : compile
  • dynamic : run-time.

Check (variable type)

Type checking : what ?

Type checking strictness:

  • strong typing (strong type check) : variables have specific data types, they're bound to a particular data type
  • weak typing (weak type check) : variables are not of a specific data type
In a strong typing PL

Compare

Comparison rules (equality, conditional expression / boolean ) came first in a weakdynamic typing PL, because it should be lax enough to compare (evaluate an expression made of) different types. An strong typing PL would simply reject such an operation (whether at compile time or a run time).

Conversion rules

Equality

Pro / Con

Static - Dynamic

Name Pro Con
Static No shadowing More code (variable declaration)
Dynamic Less code (no variable declaration) Unwilling shadowing (semantic checker lessens risk)

Strong - Weak

Name Pro Con
Strong Less errors More errors (type mismatch)
Weak Less code (deal with multiple types at once) Unwilling results (forget implicits conversion rules)
⚠️ **GitHub.com Fallback** ⚠️