AndroidPub
Published in

AndroidPub

Magic lies here - Statically vs Dynamically Typed Languages

Type Checking

a = “5” + 2;

Static typed languages

Type declaration constraints

Java Example

int data;
data = 50;
data = “Hello World!”; // causes an compilation error

Advantages:

  • A large class of errors are caught in the early stage of development process.
  • Static typing usually results in compiled code that executes more quickly because when the compiler knows the exact data types that are in use, it can produce optimized machine code (i.e. faster and/or using less memory).

Dynamically typed languages

Type declaration constraints

Python Example

data = 10;
data = “Hello World!”; // no error caused

Advantages:

  • Implementations of dynamically type-checked languages generally associate each run time object with a type tag (i.e., a reference to a type) containing its type information. This run-time type information (RTTI) can also be used to implement dynamic dispatch, late binding, down-casting, reflection, and similar features.
  • The absence of a separate compilation step means that you don’t have to wait for the compiler to finish before you can test your code changes. This makes the debug cycle much shorter and less cumbersome.

Strongly typed languages

Python is strong-typed, and so is Java.

Python Example

temp = “Hello World!”
temp = temp + 10; // program terminates with below stated error

Weakly typed languages

PHP is weakly-typed, and so is C.

PHP Example

$temp = “Hello World!”;
$temp = $temp + 10; // no error caused
echo $temp;

Conclusion

--

--

The (retired) Pub(lication) for Android & Tech, focused on Development

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store