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 quantum nonlocality as "spooky action at a distance".
Software bugs due to "action at a distance" may arise because a program component is doing something at the wrong time, or affecting something it should not. It is very difficult, however, to track down which component is responsible. Side effects from innocent actions can put the program in an unknown state, so local data is not necessarily local. The solution in this particular scenario is to define which components should be interacting with which others. A proper design that accurately defines the interface between parts of a program, and that avoids shared states, can largely eliminate problems caused by action at a distance.
This example, from the Perl programming language, demonstrates an especially serious case of action at a distance:
Array indices normally begin at 0 because the value of $[
is normally 0; if you set $[
to 1, then arrays start at 1, which makes Fortran programmers happy, and so we see examples like this in the perl(3)
man page: