Nov 9, 2015

Statically typed Versus Dynamically typed Languages

One of the fundamental language design choices is static versus dynamic typing.The word “typing” is used in many contexts in software.
A type system is a tractable syntactic method for preserving the absence of certain program behaviours by classifying phrases according to the kinds of values they compute. —Benjamin C. Pierce, Types and Programming Languages (MIT Press, 2002)
Considering various parameters, difference between Static and Dynamic typed languages are as follows:-

1. Binding philosophy:- 

In statically typed languages(or static typing), a variable is bound to a particular type for its lifetime.Its type can’t be changed and it can only reference type-compatible instances. Suppose, if a variable refers to a value of type A, you can’t assign a value of a different type B to it, unless B is a subtype of A, for some reasonable definition of “subtype.”
In dynamically typed languages(or dynamic typing), the type is bound to the value, not the variable. So, a variable might refer to a value of type A, then be reassigned later to a value of an unrelated type X.

2. Evaluation of "Type of variable":-

In dynamically typed languages the type of a variable is evaluated when it is used during runtime, while in a statically typed language the type is evaluated at parse time. That's why, in static typed languages - type is fixed at compile time and in dynamically typed languages type of variable can be changed.

3. Productivity :-

Dynamically typed languages shows productivity advantages over statically typed languages.In dynamically typed languages,write code lines a little quicker because we do not have to specify type every time.On the other hand,in statically typed languages we need to specify type every time for new variables.

4. Performance optimization:-

Optimizing the performance of a dynamic language is more challenging than for a static language. In a static language, optimizers can exploit the type information to make decisions. In a dynamic language, fewer such clues are available for the optimizer, making optimization choices harder. If we need very high performance, static languages are probably a safer choice.

5. Documentation and development perspective:-

Explicit type information in static code promotes better “self documentation” which can be important for communicating intent among developers.Considering type information decision may slow down daily design decisions however, thinking through the types in the application can result in a more coherent design over time.

7. Examples of languages:-

Statically typed languages include Ada, C, C++, C#, JADE, Java, Fortran, Haskell, ML, Pascal, Perl and Scala.
Dynamically typed languages include Groovy, JavaScript, Lisp, Lua, Objective-C, Perl, PHP, Prolog, Python, Ruby, Smalltalk and Tcl.

A design consideration Strong versus Weak typing:- 

In strong typing, every variable (for static typing) or value (for dynamic typing) must have an unambiguous type. Scala, Java, and Ruby are predominantly strongly typed languages.
In weak typing, a specific type is not required.C and Perl, are more weakly typed.
Location: Hyderabad, Telangana, India