Type-Safe vs Dynamically Typed Programming Languages

So a lot of my posts include Python code. Python is a powerful, dynamically typed, free application programming language.

Programming languages are either type-safe or dynamically typed. One setting isn’t necessarily better than the other. It all just depends on your project and what you are trying to accomplish.

Type-Safe (Statically typed)

A variable type (int, unsigned int, double, float, etc.) must be explicitly stated when a variable is declared. The variable is fixed at compile time which allows the compiler then uses this supplied information to ensure the right data is used in the right context. Languages such as C, C+ and Java are type-safe.

Pros:

  • Less bugs (There is no chance of misreading a variable)
  • Safer programming
  • Easier to manage complexity in large projects (Everyone is aware of types and their purpose)
  • More control over types (You state the type, you are in control over exactly how the compiler sees it)

Cons:

  • Decreased flexibility
  • Not as recyclable (It’s not as easy to reuse your code for multiple purposes)

 Good For:

  • Complicated algorithms and data structures which require strict low-level controls
  • Memory sensitive large dataset manipulation
  • Well-defined functions that are likely not to change much over time
  • Large development teams

Dynamically Typed

Variables are not declared with a given type. Types are basically determined by the compiler. These languages normally include extensive run-time checks to prevent most type errors.

Pros:

  • Very flexible
  • Easily Recyclable
  • Quick development speed and turn-around time
  • Reduces amount of overall code leading to possible reduction in bugs

Cons:

  • Can have some undesirable effects on the code (If the wrong type is understood in a situation, some funky things can happen)
  • More prone to human failures such as typing errors (Say you mistyped a variable, it might be seen as a new variable all together in a dynamic setting)
  • Decreased efficiency due to run-time checks

Good for:

  • Connecting different components or languages together
  • Creating graphical user interface
  • Text manipulation (Concatenating, regular expressions, search, etc.)
  • Ever changing code
  • Small segments of CPU-time intensive work
  • Automatic memory administration
  • Web server communications
  • Consistent performance across OS platforms (meaning I can run the script the same on Windows, OSX, Linux, Unix etc.)

Not to Be Confused With… 

In addition, there is also something known as weakly and strongly typing (totally different concept from the type-safe/dynamic stuff). This refers to one type being able to be used as another type. A strong language will not let a string all of a sudden act as an integer. A weak language will allow this, mostly due to unintentionally loopholes. Languages such as Pearl and C are known for being weakly typed while Python is a strongly typed language.                     

People will argue one over the other, similar to the whole Mac vs PC debate, in reality both benefit and serve different programming objective purposes.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

Time limit is exhausted. Please reload the CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.