What is the difference between statically typed an

2018-12-31 06:37发布

I hear a lot that new programming languages are dynamically typed but what does it actually mean when we say a language is dynamically typed vs. statically typed?

14条回答
看淡一切
2楼-- · 2018-12-31 07:28

dynamically typed language helps to quickly prototype algorithm concepts without the overhead of about thinking what variable types need to be used (which is a necessity in statically typed language).

查看更多
零度萤火
3楼-- · 2018-12-31 07:29
  • In a statically typed language, a variable is associated with a type which is known at compile time, and that type remains unchanged throughout the execution of a program. Equivalently, the variable can only be assigned a value which is an instance of the known/specified type.
  • In a dynamically typed language, a variable has no type, and its value during execution can be anything of any shape and form.
查看更多
冷夜・残月
4楼-- · 2018-12-31 07:30

Statically typed languages type-check at compile time and the type can NOT change. (Don't get cute with type-casting comments, a new variable/reference is created).

Dynamically typed languages type-check at run-time and the type of an variable CAN be changed at run-time.

查看更多
君临天下
5楼-- · 2018-12-31 07:31

Statically typed languages like C++, Java and Dynamically typed languages like Python differ only in terms of the execution of the type of the variable. Statically typed languages have static data type for the variable, here the data type is checked during compiling so debugging is much simpler...whereas Dynamically typed languages don't do the same, the data type is checked which executing the program and hence the debugging is bit difficult.

Moreover they have a very small difference and can be related with strongly typed and weakly typed languages. A strongly typed language doesn't allow you to use one type as another eg. C and C++ ...whereas weakly typed languages allow eg.python

查看更多
大哥的爱人
6楼-- · 2018-12-31 07:31

Static Typing: The languages such as Java and Scala are static typed.

The variables have to be defined and initialized before they are used in a code.

for ex. int x; x = 10;

System.out.println(x);

Dynamic Typing: Perl is an dynamic typed language.

Variables need not be initialized before they are used in code.

y=10; use this variable in the later part of code

查看更多
怪性笑人.
7楼-- · 2018-12-31 07:32

Statically typed programming languages do type checking (i.e. the process of verifying and enforcing the constraints of types) at compile-time as opposed to run-time.

Dynamically typed programming languages do type checking at run-time as opposed to compile-time.

查看更多
登录 后发表回答