What is the Difference Between Static and Dynamic Types?

by admin on June 26, 2008

Programming languages, especially object oriented programming languages, classify values and expressions into types. What is the difference between static and dynamic types?

First, the term type refers to the kind of data type in a computer program. When you use static types, you use variables that don’t need to be defined before they’re used. Java, C and C++ are all examples of languages that use statically typed variables. For example, if you create an int variable in Java, the compiler knows what it is, and how to deal with it.

In dynamically typed programming languages, variables need to be defined before they can be used. Python and PHP are examples of dynamically typed programming languages. You don’t need to declare the variable ahead of time, but you define it when you first use it.

The main difference between static and dynamic typing is when a complier checks to find errors. With a statically typed language, the compiler checks to make sure that all the variables have been properly declared and used at compile time. If there are type errors, the program won’t even compile.

With a dynamically typed language, the program encounters variable type errors at runtime. The program could be working fine, and then suddenly crash because of a type error.

Leave a Comment

Previous post:

Next post: