Static typed and Dynamic typed programming

24th Jun 2019, 7:49 AM
sree harsha
sree harsha - avatar
1 Answer
+ 2
Statically typed programming languages are programming languages which enforce type systems on the programmer at compile-time. Dynamically typed languages do not. This means that when the program is being run, a statically-typed language will already know what type of data every variable is, whereas a dynamically typed language can not make that same guarantee. Some examples of statically typed languages are Java, C, C++, and Rust. Some examples of dynamically typed languages are Javascript, Lua, and Python. I personally prefer statically-typed languages but I'll try to give you the pro's and con's of both: The reason why some people prefer statically typed languages is performance and safety. For performance, statically-typed languages do not have to do any type-checking at runtime. If I call var1 + var2 in a statically-typed language, the compiler can figure out what the "+" sign means, and then simple put the functionality into the executable binary. In a dynamically typed language, all of that checking is done at runtime, so the program needs to figure out if the variables are strings or ints or floats before it can actually preform the calculation. Also, if the two types were incompatible with one another, a statically-typed language would throw an error at compile time, allowing the programmer to fix the bug before it got into production code. In a dynamically-typed language, that could not happen. The main reason people would prefer dynamically-typed languages is for flexibility and easiness. It's much easier to simply not have to worry about type-checking. Additionally, it's useful to be able to treat a variable as multiple different types of data. For example, I might want to assign a variable to a string value in one case, but then to an int value in another case. Or I might want to return many different data types from a function depending on what's passed into the function. These things could not happen in a static language because the compiler NEEDS to know every variables type for certain.
30th Jun 2019, 10:02 AM
Jack McCarthy
Jack McCarthy - avatar