静态/动态类型与静态/动态绑定

发布于 2024-10-08 13:45:53 字数 27 浏览 3 评论 0原文

大家这4个术语有什么区别,能举个例子吗?

everyone what is the difference between those 4 terms, can You give please examples?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

醉城メ夜风 2024-10-15 13:45:53

静态动态是行话,指的是解决某些编程元素的时间点。 静态表示解析在程序构建时发生。 动态表示解析在程序运行时发生。

静态和动态类型

类型是指由于数据值之间的差异而导致的程序结构的变化:整数、字符、浮点数、字符串、对象等。这些差异可能会产生许多影响,例如:

  • 内存布局(例如,int 为 4 字节,double 为 8 字节,对象为更多字节)
  • 执行的指令(例如,添加小整数的基本操作、添加大整数的库调用)
  • 程序流(简单的子例程调用约定与多方法的散列调度)

静态类型意味着在构建时生成的程序的可执行形式将根据程序中找到的数据值的类型而变化。 动态类型意味着生成的代码将始终相同,无论类型如何 - 执行中的任何差异都将在运行时确定。

请注意,很少有真正的系统要么纯粹是其中一种,要么纯粹是另一种,这只是哪个是首选策略的问题。

静态和动态绑定

绑定是指程序文本中的名称与它们所引用的存储位置的关联。在静态绑定中,这种关联是在构建时预先确定的。对于动态绑定,这种关联直到运行时才确定。

真正的静态绑定几乎已经绝迹。例如,早期的汇编程序和 FORTRAN 会完全预先计算所有变量和子例程位置的确切内存位置。这种情况并没有持续多久,随着变量的堆栈和堆分配以及子例程的动态加载库的引入。

因此,我们必须对定义采取一定的自由度。这里重要的是这个概念的精神:静态绑定程序尽可能多地预先计算存储布局,这在现代虚拟内存、垃圾收集、单独编译的应用程序中是可行的。动态绑定的程序会尽可能晚地等待。

一个例子可能会有所帮助。如果我尝试调用方法 MyClass.foo(),静态绑定系统将在构建时验证是否有一个名为 MyClass 的类,并且该类具有一个方法称为foo。动态绑定系统将等到运行时才查看其中一个是否存在。

对比

静态策略的主要优点是程序翻译者更了解程序员的意图。这使得更容易:

  • 在构建阶段尽早捕获许多常见错误

  • 构建重构工具

  • 招致在构建时仅确定一次程序的可执行形式所需的大量计算成本

成本动态策略的主要优势在于它们更容易实施,这意味着:

  • 可以以静态策略的一小部分成本创建工作动态环境

  • 添加静态检查可能非常困难的语言功能会更容易

  • 更容易处理需要自修改代码的情况

Static and dynamic are jargon words that refer to the point in time at which some programming element is resolved. Static indicates that resolution takes place at the time a program is constructed. Dynamic indicates that resolution takes place at the time a program is run.

Static and Dynamic Typing

Typing refers to changes in program structure that are due to the differences between data values: integers, characters, floating point numbers, strings, objects and so on. These differences can have many effects, for example:

  • memory layout (e.g. 4 bytes for an int, 8 bytes for a double, more for an object)
  • instructions executed (e.g. primitive operations to add small integers, library calls to add large ones)
  • program flow (simple subroutine calling conventions versus hash-dispatch for multi-methods)

Static typing means that the executable form of a program generated at build time will vary depending upon the types of data values found in the program. Dynamic typing means that the generated code will always be the same, irrespective of type -- any differences in execution will be determined at run-time.

Note that few real systems are either purely one or the other, it is just a question of which is the preferred strategy.

Static and Dynamic Binding

Binding refers to the association of names in program text to the storage locations to which they refer. In static binding, this association is predetermined at build time. With dynamic binding, this association is not determined until run-time.

Truly static binding is almost extinct. Earlier assemblers and FORTRAN, for example, would completely precompute the exact memory location of all variables and subroutine locations. This situation did not last long, with the introduction of stack and heap allocation for variables and dynamically-loaded libraries for subroutines.

So one must take some liberty with the definitions. It is the spirit of the concept that counts here: statically bound programs precompute as much as possible about storage layout as is practical in a modern virtual memory, garbage collected, separately compiled application. Dynamically bound programs wait as late as possible.

An example might help. If I attempt to invoke a method MyClass.foo(), a static-binding system will verify at build time that there is a class called MyClass and that class has a method called foo. A dynamic-binding system will wait until run-time to see whether either exists.

Contrasts

The main strength of static strategies is that the program translator is much more aware of the programmer's intent. This makes it easier to:

  • catch many common errors early, during the build phase

  • build refactoring tools

  • incur a significant amount of the computational cost required to determine the executable form of the program only once, at build time

The main strength of dynamic strategies is that they are much easier to implement, meaning that:

  • a working dynamic environment can be created at a fraction of the cost of a static one

  • it is easier to add language features that might be very challenging to check statically

  • it is easier to handle situations that require self-modifying code

紫瑟鸿黎 2024-10-15 13:45:53

类型 - 指变量类型以及是否允许变量在程序执行期间更改类型

http://en。 wikipedia.org/wiki/Type_system#Type_checking

绑定 - 正如您在下面所读到的,这可以指变量绑定或库绑定

http://en.wikipedia.org/wiki/Binding_%28computer_science%29#Language_or_Name_binding

Typing - refers to variable tyes and if variables are allowed to change type during program execution

http://en.wikipedia.org/wiki/Type_system#Type_checking

Binding - this, as you can read below can refer to variable binding, or library binding

http://en.wikipedia.org/wiki/Binding_%28computer_science%29#Language_or_Name_binding

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文