Action at a distance (computer science)

Action at a distance (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.

The term is based on the physics concept of the same name, where particles may be created that cancel each other out. Such particles instantaneously communicate information across space regardless of distance in what Albert Einstein called "spooky action at a distance".

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.

Example

From [http://www.perl.com/pub/a/1999/11/sins.html Sins of Perl Revisited] by Mark-Jason Dominus:

:"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:"

foreach $num ($ [ .. $#entry) { print " $num '",$entry [$num] ,"' ";}

:"And of course you could set $ [ to 17 to have arrays start at some random number such as 17 or 4 instead of at 0 or 1. This was a great way to sabotage module authors."

:"Fortunately, sanity prevailed. These features are now recognized to have been mistakes. The perl5-porters mailing list now has a catchphrase for such features: they're called "action at a distance". The principle is that a declaration in one part of the program shouldn't drastically and invisibly alter the behavior of some other part of the program. Some of the old action-at-a-distance features have been reworked into safer versions. For example, In Perl 5, you are not supposed to use $*. Instead, you put /m on the end of the match operator to say that the meanings of ^ and $ should be changed just for that one regex."

Action at a distance across objects

Proper object oriented programming involves design principles that avoid action at a distance.The Law of Demeter states that an object should only interact with other objects near itself. Should action in a distant part of the system be required then it should be implemented by propagating a message. Proper design severely limits occurrences of action at a distance, contributing to maintainable programs. Pressure to create an object orgy results from poor interface design, perhaps taking the form of a God object, not implementing true objects, or failing to heed the Law of Demeter.

One of the advantages of functional programming is that action at a distance is de-emphasised, sometimes to the point of being impossible to express at all in the source language.

Being aware of the danger of allowing action at a distance into a design, and being able to recognize the presence of action at a distance, is useful in developing programs that are correct, reliable and maintainable. Given that the majority of the expense of a program may be in the maintenance phase, and that action at a distance makes maintenance difficult, expensive and error prone, it is worth effort during design to avoid.

ee also

*Law of Demeter
*Object orgy
*God object
*Loose coupling
*State pattern
*Accumulate and fire
*COME FROM

References

*"Perl Design Patterns Book"


Wikimedia Foundation. 2010.

Игры ⚽ Поможем сделать НИР

Look at other dictionaries:

  • Action at a distance — may refer to: * Action at a distance (physics), the instantaneous interaction of two objects which are separated in space * Action at a distance (computer science), an anti pattern …   Wikipedia

  • Computer-supported collaboration — (CSC) research focuses on technology that affects groups, organizations, communities and societies, e.g., voice mail and text chat. It grew from cooperative work study of supporting people s work activities and working relationships. As net… …   Wikipedia

  • computer — computerlike, adj. /keuhm pyooh teuhr/, n. 1. Also called processor. an electronic device designed to accept data, perform prescribed mathematical and logical operations at high speed, and display the results of these operations. Cf. analog… …   Universalium

  • Science and technology in the People's Republic of China — has been growing rapidly. As China develops and becomes more connected to the global economy, the government has placed a stronger emphasis on science and technology as an integral part of the socio economic development of the country. This has… …   Wikipedia

  • Computer-assisted language learning — (CALL) is succinctly defined in a seminal work by Levy (1997: p. 1) as the search for and study of applications of the computer in language teaching and learning .[1] CALL embraces a wide range of ICT applications and approaches to teaching… …   Wikipedia

  • Computer-supported collaborative learning — (CSCL) is a pedagogical approach wherein learning takes place via social interaction using a computer or through the Internet. This kind of learning is characterized by the sharing and construction of knowledge among participants using technology …   Wikipedia

  • Science fiction convention — Fans talk after panel Science fiction conventions are gatherings of fans of various forms of speculative fiction including science fiction and fantasy. Historically, science fiction conventions had focused primarily on literature, but the purview …   Wikipedia

  • History of science — History of science …   Wikipedia

  • AMA Computer University — Infobox University name = motto = Never rest on one s laurels established = October 15, 1980 type = Private president = Amable Aguiluz IX city = Quezon City state = Metro Manila country = Philippines address = Villa Arca, Project 8 undergrad =… …   Wikipedia

  • Vidya Academy of Science and Technology — (VAST), locally also known as Vidya Engineering College or Vidya College or simply Vidya, is a new generation private self financing engineering college functioning in Thrissur District in Kerala. The college is located in a 30 acre lush green… …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”