Introduction to Static and Dynamic Typing

One important concept to understand whenlanguages are more flexible. Since more errors
programming is the difference between static andtend to occur at run-time than compile-time,
dynamic typing. Static typing can be seen inthese programs are often more difficult to debug.
languages such as Java or C++, and dynamicAs such, the principle of unit testing, or testing
typing is used in languages such as Python or PHP.one piece of the program at a time, is extremely
Each has its advantages and disadvantages.important when working with a dynamic language.
Static typing, because type checking is performedNote that static and dynamic typing are not the
during compilation, allows for errors to be caughtsame as strong and weak typing. Strong typing
early in the development process. This way, thesimply means that variable types are required,
checks do not need to be performed each timeand weak typing is when variables do not have a
the program is run and can make programspecific type. Many people assume static and
execution more efficient. Variables cannot bestrong typing are the same thing as are dynamic
created on the fly as they are needed; theyand weak typing, but this is not necessarily true.
must first be defined. Some programmers dislikeIn Python, variables can be dynamically created as
this extra step in coding, but it often makes forthey are needed, but it is not a weak language as
safer, more predictable program outcomes.variables have types.
In dynamic typing, type checking is done atAs you can see, understanding the difference
run-time rather than compile-time. As a result,between static and dynamic typing is an
these languages can produce more run-timeimportant aspect of programming, and can help
errors and have less guarantees with how theyou chose the language which best suits the
program will run, since certain "invalid" programsneeds of your application. Each has its own pros
which a static typing language would reject atand cons, but both are widely used.
compilation are allowed to run. However, dynamic