What are Statically and Dynamically Typed Languages ?

Statically and Dynamically Typed Languages


The topic of difference between statically typed language and dynamically typed language have proved to be of immense importance to all the beginner as well as intermediate coders and developers. Let's start with understanding the concept with examples.

Statically typed languages include C , C++ ,  Java and many more while dynamically typed languages include Python, JavaScript etc.

Statically Typed Languages


Dynamically Typed Languages

Starting with statically typed languages let us suppose that we want to declare a integer type variable in C/C++/Java Language:


In  C :


In C++ :


In Java :


Now Suppose We Want to perform the same action in Python and JavaScript programming languages:

 

 In Python : 



In JavaScript  : 


 

In C/C++/Java, Compiler is used for Translation of code to machine code (Just-in-Time Compiler in case of JAVA), the data type need to be mentioned at the compile time so that when code get compiled ,the compiler can decide how much memory is to be assigned to any such variable( 4 bytes for an integer variable in C/C++(32-bit Architecture) and 1 byte for a character variable) before the actual execution takes place .While we have another alternative for this is that we can use Dynamic Memory Allocation  for taking input(or assigning memory to variable) in runtime but in that case too we have to explicitly mention or declare the specific pointer/reference variable’s data type of what type of variable’s address it is going to store. 


Like in C :


In C++ : 


 

So That’s Why C,C++ and Java are some of the examples of Statically Typed Languages.

 

As we have enough knowledge about statistically typed languages, we can move forward to Dynamically Typed Programming Language.

    

Unlike in C/C++/Java we don’t have to explicitly mention the data type during declaration of variables because these Languages use Interpreter in place of Compiler for their code conversion in machine code. Since, Interpreter does make any intermediate file after interpreting the code and directly execute our program instructions by reading our code line by line and sending to operating system,the data type of the variable gets decided at the runtime by the type of the value we are assigning to it during program execution.Since Data Types of variables are decided during runtime(Dynamically) these languages are called Dynamically types languages.

 

Not only variables but functions can also be implemented using this concept. Concisely, in statistically typed languages the data type of arguments and parameters of functions as well as return type is to be explicitly mentioned while in case of Dynamically typed languages no such acknowledgement is required.



Comments

Post a Comment