Statically typed language
and Dynamically typed language.
By Ayush garg
There are
lots of programming languages in world. Every language follow some paradigm (A
guild line follow to make program). For example c follow procedure oriented paradigm,
C++ and java follow object oriented paradigm.
Similarly statically type and dynamically typed are another paradigm of
programming language.
Important note
– sometime programmer get confuse between static or dynamic typed language and
static or dynamic memory allocation. Both are totally different concept. Static or dynamic typed language is the
paradigm of programming language and static or dynamic memory allocation is all
the allocation of the memory of the variable.
To explain
this concept I am going to use the python, C, C++, and Java language.
If you don’t
know these or anyone of these languages doesn’t worry consider the program as a pseudo code.
So let’s
begin.
Statically typed language-
The
programming language in which programmer has to define the data type of the
variable is statically typed language. By defining type of the variable, the size
of the variable and what kind of data will be stored by the variable is fixed
is fixed at the compile time.
Consider the
following code snippet-
Code in C /C++
/ Java
int x=5;
int y=5;
int z=x + y;
Here I define
the type of each variable. If I don’t define the type of the variable an error
occurs in my program.
If I write
like that
int x=”My Article”;
Error occurs
in my program. Because the type of the variable is fixed at compile. And int
type variable only capable to store the integer value.
Dynamically typed language-
The programming language
in which programmer doesn’t need to define the data type of the variable is
dynamically typed language. The size and the type of the data store by the
variable are decided at run time.
Consider the
following code snippet-
Code in
python
x=5
y=5
z=x+y
In the above
code I don’t define the data type. So the compiler decides the data type of the
variable at the run time it compile the code correctly.
If I write
following code
x=”My Article”
It runs
because the data type of the variable is decided at the run time.
Each and
every paradigm has some merit and some demerit. So statically typed and
dynamically typed paradigm also have some merit and demerit.
Merit and demerit
of statically typed language and dynamically typed language –
Merit of dynamically
typed language over staically typed language-
1. The length of code little bit
increase in statically typed language. The length of code is little bit small
in dynamically typed language.
2. Programmer always needs to define the data type
of the code. If the programmers forget to define the data type the variable error
occurs in statically typed language. But programmers don’t need to worry about
the data type of the variable in dynamically typed language. It all up to
compiler in dynamically typed language.
Demerit of statically typed language over statically typed language-
1. If some error occurs because of data
type, code doesn’t compile. And error generate at compile time. Which is easily
identified by the programmer in statically typed language. If some error occur
because of the data type code compile but error occur at run time. Which is not
easily identified in dynamically typed language.
2. Consider that you need to modify the
data store in the variable. So you write a code.
Consider following code
snippet.
Code in C/ C++/ Java
int x=5;
X=x+5;
In above code compile
time error occurs. Because C/ C++/ Java statically typed case sensitive
language. And x and X are different. And
here we assign the data to the X which is not defining anywhere. So these all
three language give the error “X undefined symbol”
Consider following code
snippet.
Code in python
x=5
X=x+5
In above run, no error
generates. Neither at compile time nor at run time. The new variable X come
into a memory which hole the modify value in it.
Important note- It is not necessary programming language only follow the one paradigm. Programming language follow may be follow more then one paradigm. For example-
Java follow object oriented programming paradigm, statically typed paradigm, strong typed paradigm.
Important note- It is not necessary programming language only follow the one paradigm. Programming language follow may be follow more then one paradigm. For example-
Java follow object oriented programming paradigm, statically typed paradigm, strong typed paradigm.
Thank you.
If you have any suggestion for
improvement or found mistake or if you
Like please writer in comment
in the comment section and share it.
Comments
Post a Comment