静态和动态编程语言之间的区别 [英] Difference between static and dynamic programming languages
本文介绍了静态和动态编程语言之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
静态和动态编程语言有什么区别?我知道这完全与类型系统有关,但我正在寻找更明确的说明.
What is the different between static and dynamic programming languages? I know that it is all about type systems but I’m looking for more clear clarifications.
推荐答案
静态打字
静态类型意味着在运行程序之前已知类型并检查其正确性.这通常由语言的编译器完成.例如,以下 Java 方法会导致编译错误,在您运行程序之前:
public void foo() {
int x = 5;
boolean b = x;
}
动态打字
动态类型意味着只有在程序运行时才知道类型.例如,以下 Python(3,如果重要)脚本可以毫无问题地运行:
Dynamic Typing
Dynamic typing means that types are only known as your program is running. For example, the following Python (3, if it matters) script can be run without problems:
def erroneous():
s = 'cat' - 1
print('hi!')
它确实会输出hi!
.但是如果我们调用errors
:
It will indeed output hi!
. But if we call erroneous
:
def erroneous():
s = 'cat' - 1
erroneous()
print('hi!')
TypeError
将在 运行时 error
被调用.
A TypeError
will be raised at run-time when erroneous
is called.
这篇关于静态和动态编程语言之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文