What's advantages of declaring variables?

When I learn Java, I was wondering why variables should be declared. But when I search about this, I noticed that some languages are not needed to declare variables. So I was thinking okay, why is it different? what's the advantage of declaring data types? This is the page for summarizing and organizing my knowledge of above questions.

I organized my thought about data types here.

Dynamically typed and Statically typed languages

There are two categories when programming languages are categorized: Dynamically typed and Statically typed languages.

Dynamically typed languages are languages that variables not need to be defined before they are used. On the other hand, Statically typed languages are languages that variables needs to be defined before they are used.

  • Dynamically typed Languages : JavaScript / Python / Ruby / etc...
  • Statically typed languages : C / C++ / C# / Java / Scala / Swift

What is the advantages of declaring variables?

Here's the advantages of Declaring variables or not declaring variables.

Advantages not to declare variables

  • The amount of code is reduces

Programers don't need to write int, String, etc

  • The difficulty of programming become easy

In statically typed languages, it become error if programmer writes different data types in variables (e.g. adding String to numbers)

Advantages to declare variables

  • Identifying some types of errors easily because of visibility of data types

you might be easy to identify errors if variables A declare as String and actually contains numbers.

  • Optimizing memory

Computer can identify how much memory space should be prepared if data types are written.

  • Increasing the speed of arithmetic processing

Computer can identify if it's integer or float or any types of numbers in advance.

Please let me know if there are also different advantages to declare or not to declare variiables.

Related posts