gpt4 book ai didi

java - 这个 JEP 中的 "action at a distance"是什么?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:39:24 26 4
gpt4 key购买 nike

这里我说的是this JEP .文中多次提到“远距离行动”;例如:

Excluding locals with no initializers eliminates "action at a distance" inference errors, and only excludes a small portion of locals in typical programs.

或:

Similarly, we also could have taken all assignments into account when inferring the type, rather than just the initializer; while this would have further increased the percentage of locals that could exploit this feature, it would also increase the risk of "action at a distance" errors.

我了解 JEP 的大部分内容,但那部分内容让我望而却步。

这里的“远距离行动”是什么意思?

最佳答案

来自维基百科文章 "Action at a distance (computer programming)"

In computer science, action at a distance is an anti-pattern (a recognized common error) in which behavior in one part of a program varies wildly based on difficult or impossible to identify operations in another part of the program. The way to avoid the problems associated with action at a distance are a proper design, which avoids global variables and alters data in a controlled and local manner, or usage of a pure functional programming style with referential transparency.

The term is based on the concept of action at a distance in physics, which may refer to a process that allows objects to interact without a mediator particle such as the gluon. In particular, Albert Einstein referred to this effect in quantum mechanics as "spooky action at a distance".

在这种情况下,它指的是没有初始化表达式的变量,如下所示:

var list;

// many lines of code

list = new ArrayList<String>();

虽然可以从代码后面的赋值表达式进行变量类型推断,但这样做会使代码遭受“远距离操作”引起的问题:这对代码的读者来说根本不是显而易见的编码局部变量的类型,这可能会导致错误。

关于java - 这个 JEP 中的 "action at a distance"是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35909928/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com