Static and Dynamic Typed Languages

Type

  • In programming, a data type is what we tell the computer the type of data it’s dealing with, e.g. a string, number, or object. When defining a variable, a computer needs both the name and the type of data before it can store and process it. This way it knows much much memory to set aside, how to access it and how to change it.
  • Each programming language has a different way of handling how it assigns data types (static vs. dynamic) and how flexible (strong vs. weak) they are when trying to change them. You might have read conflicting information about “static” vs “dynamic” data types, as well as “strong” vs “weak” data types. They’re not the same thing, and a language can include a combination of static/dynamic and strong/weak data types

Static vs. Dynamic

  • I think this is not accurate. if you have type inference (ML, OCaml, F#, Haskell…), type definitions are not always necessary
  • Static Typed language do type-check at compile-time
  • Dynamic Typed language do type-check on-the-fly
StaticDynamic
StrongJavaPython
WeakC/C++JavaScript

Strong vs. Weak

Strong vs. Weak defines how flexibly a language allows operations between data types. For example, strongly typed languages will not allow you to add a float to an integer, without you converting it first, even though they are both numbers. On the other hand, a weak language will try its best to accomodate what the programmer is asking and perform these operations.

  • Weak typed language can do implicit coercion, and strong typed language disallow that
StaticDynamic
StrongJavaPython
WeakC/C++JavaScript

Compiled vs. Interpreted

  • “When source code is translated”

    • Compiled: Code translated before run-time
    • Interpreted: Code translated on the fly, during execution
  • So all the languages can be both compiled and interpreted

Why Should We Care About Data Types?

  • how to do computation based on the types
  • knowing types helps optimization