Language Types: Static vs Dynamic | Weak vs Strong

Static Typing

A language that checks the types and looks for type errors during compile time.

Dynamic Typing

A language that checks the types and looks for type errors during runtime.

Static vs Dynamic

  1. Static typing will validate all the types before running the program
    Dynamic typing will validate all the types while on the running program.
  2. Static typing, if using incorrect types, will error on compilation, and not even going to run.
    Dynamic typing, if using incorrect types, will still run, but the error only occurs when the particular line of code is executed.
  3. Static typing: C++, Java, and Go
    Dynamic typing: Ruby, JavaScript, and PHP

Weak Typing

Weak typing is a type that somewhat chill/relax. The type that is not strict.
Operations can be done without we declare the right type and casting can be done pretty easily.

5 + '5';          // '55'
2 * '3'; // 6
7 + true; // 8
Number('aaa!!'); // NaN
Boolean(1); // true
String(false); // 'false'

Example: JavaScript and C

Strong Typing

Strong typing is a type that strict. A type can only do what that type should behave.

5 + '5'  // No instance for (Num Char) arising from a use of `+'
(int)'5' // Variable not in scope: int :: Char -> t
5 + 5 // 10

Example: Clojure and Haskell

Weak ←→Strong

Weak and strong typing is a spectrum like introvert<->extrovert.
Not every language is either at the end of a strong spectrum or the end of a weak spectrum.

Language like Python might be strong typing more than Js, Haskell is stronger than C.

Conclusion

Static and Dynamic typing is about when.
Static: when on the compilation
Dynamic: when on runtime

Weak and Strong typing is about how serious.
Weak: relax and chill
Strong: strict and literal

Personal Growth Enthusiast | Software Developer | Love sharing | Check my stuff out!