Advice In Aspect-oriented Programming
   HOME

TheInfoList



OR:

In
aspect Aspect or Aspects may refer to: Entertainment * ''Aspect magazine'', a biannual DVD magazine showcasing new media art * Aspect Co., a Japanese video game company * Aspects (band), a hip hop group from Bristol, England * ''Aspects'' (Benny Carter ...
and
functional programming In computer science, functional programming is a programming paradigm where programs are constructed by Function application, applying and Function composition (computer science), composing Function (computer science), functions. It is a declar ...
, advice describes a class of functions which modify other functions when the latter are run; it is a certain function, method or procedure that is to be applied at a given
join point In computer science, a join point is a point in the control flow of a program where the control flow can arrive via two different paths. In particular, it's a basic block that has more than one predecessor. In aspect-oriented programming a set of ...
of a program.


Use

The practical use of advice functions is generally to modify or otherwise extend the behavior of functions which cannot be easily modified or extended. The
Emacspeak Emacspeak is a free computer application, a speech interface, and an audio desktop (as opposed to a screen reader). It employs Emacs (which is written in C), Emacs Lisp, and Tcl. Developed principally by T. V. Raman (himself blind since chil ...
Emacs Emacs , originally named EMACS (an acronym for "Editor MACroS"), is a family of text editors that are characterized by their extensibility. The manual for the most widely used variant, GNU Emacs, describes it as "the extensible, customizable, s ...
-addon makes extensive use of advice: it must modify thousands of existing Emacs modules and functions such that it can produce audio output for the blind corresponding to the visual presentation, but it would be infeasible to copy all of them and redefine them to produce audio output in addition to their normal outputs; so, the Emacspeak programmers define advice functions which run before and after. Another Emacs example; suppose after one corrected a misspelled word through
ispell Ispell is a spelling checker for Unix that supports most Western languages. It offers several interfaces, including a programmatic interface for use by editors such as Emacs. Unlike GNU Aspell, ispell will only suggest corrections that are based ...
, one wanted to re-spellcheck the entire buffer. ispell-word offers no such functionality, even if the spellchecked word is used a thousand times. One ''could'' track down the definition of ispell-word, copy it into one's Emacs, and write the additional functionality, but this is tedious, prone to broken-ness (the Emacs version will get out of sync with the actual Ispell Elisp module, if it even works out of its home). What one wants is fairly simple: just to run another command after ispell-word runs. Using advice functions, it can be done as simply as this: (defadvice ispell (after advice) (flyspell-buffer)) (ad-activate 'ispell t)


Implementations

A form of advices were part of
C with Classes C++ (pronounced "C plus plus") is a high-level general-purpose programming language created by Danish computer scientist Bjarne Stroustrup as an extension of the C programming language, or "C with Classes". The language has expanded significan ...
in the late 1970s and early 1980s, namely functions called call and return defined in a class, which were called before (respectively, after) member functions of the class. However, these were dropped from
C++ C++ (pronounced "C plus plus") is a high-level general-purpose programming language created by Danish computer scientist Bjarne Stroustrup as an extension of the C programming language, or "C with Classes". The language has expanded significan ...
. Advices are part of the
Common Lisp Object System The Common Lisp Object System (CLOS) is the facility for object-oriented programming which is part of ANSI Common Lisp. CLOS is a powerful dynamic object system which differs radically from the OOP facilities found in more static languages such as ...
(CLOS), as :before, :after, and :around methods, which are combined with the primary method under "standard method combination". Common Lisp implementations provide advice functionality (in addition to the standard method combination for CLOS) as extensions. LispWorks supports advising functions, macros and CLOS methods. EmacsLisp added advice-related code in versio
19.28
1994.


History

The following is taken from a discussion at the mailing lis

Pascal Costanza Pascal Costanza is a research scientist at the ExaScience Lab at Intel Belgium. He is known in the field of functional programming in LISP as well as in the aspect-oriented programming (AOP) community for contributions to this field by applying AOP ...
contributed the following: The term "advice" goes back to the term ''advising'' as introduced by
Warren Teitelman Warren Teitelman (1941 – August 12, 2013) was an American computer scientist known for his work on programming environments and the invention and first implementation of concepts including Undo, Undo / Redo, spelling correction, advising, online ...
in his PhD thesis in 1966. Here is a quote from Chapter 3 of his thesis: :Advising is the basic innovation in the model, and in the PILOT system. Advising consists of inserting new procedures at any or all of the entry or exit points to a particular procedure (or class of procedures). The procedures inserted are called "advice procedures" or simply "advice". :Since each piece of advice is itself a procedure, it has its own entries and exits. In particular, this means that the execution of advice can cause the procedure that it modifies to be bypassed completely, e.g., by specifying as an exit from the advice one of the exits from the original procedure; or the advice may change essential variables and continue with the computation so that the original procedure is executed, but with modified variables. Finally, the advice may not alter the execution or affect the original procedure at all, e.g., it may merely perform some additional computation such as printing a message or recording history. Since advice can be conditional, the decision as to what is to be done can depend on the results of the computation up to that point. :The principal advantage of advising is that the user need not be concerned about the details of the actual changes in his program, nor the internal representation of advice. He can treat the procedure to be advised _as a unit_, a single block, and make changes to it without concern for the particulars of this block. This may be contrasted with editing in which the programmer must be cognizant of the internal structure of the procedure. "Advising" found its way into BBN Lisp and later into
Xerox PARC PARC (Palo Alto Research Center; formerly Xerox PARC) is a research and development company in Palo Alto, California. Founded in 1969 by Jacob E. "Jack" Goldman, chief scientist of Xerox Corporation, the company was originally a division of Xero ...
's
Interlisp Interlisp (also seen with a variety of capitalizations) is a programming environment built around a version of the programming language Lisp. Interlisp development began in 1966 at Bolt, Beranek and Newman (renamed BBN Technologies) in Cambridge, ...
. It also found its way to
Flavors Flavor or flavour is either the sensory perception of taste or smell, or a flavoring in food that produces such perception. Flavor or flavour may also refer to: Science *Flavors (programming language), an early object-oriented extension to Lis ...
, the first
object-oriented Object-oriented programming (OOP) is a programming paradigm based on the concept of "objects", which can contain data and code. The data is in the form of fields (often known as attributes or ''properties''), and the code is in the form of pro ...
extension to
Lisp A lisp is a speech impairment in which a person misarticulates sibilants (, , , , , , , ). These misarticulations often result in unclear speech. Types * A frontal lisp occurs when the tongue is placed anterior to the target. Interdental lisping ...
developed at
MIT The Massachusetts Institute of Technology (MIT) is a private land-grant research university in Cambridge, Massachusetts. Established in 1861, MIT has played a key role in the development of modern technology and science, and is one of the mo ...
. They were subsumed under the notion of method combination. Since method combination and macros are closely related, it's also interesting to note that the first macro system was described in 1963, three years before Warren Teitelman's PhD thesis.See AIM-57 at https://web.archive.org/web/20060913001624/http://www.ai.mit.edu/research/publications/browse/0000browse.shtml


See also

* Function decorator (w.r.t.
Python Python may refer to: Snakes * Pythonidae, a family of nonvenomous snakes found in Africa, Asia, and Australia ** ''Python'' (genus), a genus of Pythonidae found in Africa and Asia * Python (mythology), a mythical serpent Computing * Python (pro ...
) * Aspect-oriented software development#Advice bodies


Notes

Gregor Kiczales Gregor Kiczales is an American computer scientist. He is currently a full time professor of computer science at the University of British Columbia in Vancouver, British Columbia, Canada. He is best known for developing the concept of aspect-orient ...
comments the above as follows:


References


External links


Teitelman's PhD thesis
(AITR-221)
Interlisp reference manual
from 1974

{{aosd Aspect-oriented programming Lisp (programming language) Programming constructs Articles with example Lisp (programming language) code