Typing - GradedJestRisk/lexicon GitHub Wiki
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.
PL: programming language.
Variable:
- (type) declaration
- (value) definition (= initialized, given value)
- use (in an expression)
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.
Variables must be defined before use.
declaration is meaningless, because type is linked to a particular definition.
Type checking time:
- static : compile
- dynamic : run-time.
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
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).
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) |