What Does Aspect-Oriented Programming Mean for Functional Programmers?

What Does Aspect-Oriented Programming Mean for Functional Programmers?

What Does Aspect-Oriented Programming Mean for Functional Programmers? Meng Wang and Bruno C. d. S. Oliveira Oxford University Computing Laboratory Wolfson Building, Parks Road, Oxford OX1 3QD, UK {menw,bruno}@comlab.ox.ac.uk mers and software engineers. However, interestingly enough, the functional programming community (and, in particular, the pure Abstract functional programming community) seems to be resistant to the pandemic, with only some sporadic outbreaks happening once in Aspect-Oriented Programming (AOP) aims at modularising cross- a while. Notably, Aspectual Caml [39] makes a good attempt by cutting concerns that show up in software. The success of AOP centring its design around a classic problem, namely the expres- has been almost viral and nearly all areas in Software Engineer- sion problem. The evaluator developed there allows open exten- ing and Programming Languages have become “infected” by the sion of new language expressions and new operations at the same AOP bug in one way or another. Interestingly the functional pro- time. This two-dimensional extensibility is known to be hard to gramming community (and, in particular, the pure functional pro- achieve either in object-oriented languages or functional languages. gramming community) seems to be resistant to the pandemic. The In another work, Washburn and Weirich demonstrated functional goal of this paper is to debate the possible causes of the functional type-directed programming in AspectML [14], and showed that the programming community’s resistance and to raise awareness and extensibility of AOP is important for extensible generic program- interest by showcasing the benefits that could be gained from hav- ming [54]. AspectFun [52, 7] is another proposal for a functional ing a functional AOP language. At the same time, we identify the AOP language, where static resolution of types and advice invoca- main challenges and explore the possible design-space. tions are emphasised. Categories and Subject Descriptors D.3.2 [Programming Lan- It appears that one of the reasons for the lack of interest in func- guages]: Language Classifications—Applicative (functional) lan- tional AOP is the perceived lack of application domains. Indeed, the guages, Multiparadigm languages; D.3.3 [Programming Lan- majority of developments of AOP are based on an Object-Oriented guages]: Language Constructs and Features—Control structures (OO) environment; directly borrowing the results there, usually fea- turing heavy use of run-time reflection and mutable state, has a General Terms Languages, Design counter-effect when promoting AOP in functional programming. Keywords Functional Programming, Aspect-Oriented Program- Another notable reason for this lack of interest is the great scep- ming, Program Extensibility and Adaptability, Separation of Con- ticism that many researchers have towards AOP. As argued by cerns Steimann [47], the (fairly well accepted) defining characteristics of AOP, namely obliviousness and quantification [16], seem to be fundamentally at odds with the stated goals of improving modu- 1. Introduction larity and structure of code. When it comes to functional program- Aspect-Oriented Programming (AOP) [30] aims at improving mod- ming, fuelled by the first reason above, many (including the authors ularity through the separation of orthogonal (also know as crosscut- themselves) very often deem AOP approaches as too invasive and ting) concerns that show up in software. The success of AOP has uncontrolled. been almost viral and nearly all areas in Software Engineering and In particular, we identify the following main issues: Programming Languages (SE&PLs) have become “infected” by the AOP bug in one way or another. In fact, the article describing the • Obliviousness - AOP languages typically weave additional code original concept is currently rated the second most influential work into existing programs, potentially modifying the behaviour in all of the SE&PLs areas [36], lagging only behind the seminal of the original base programs without warning, which hinders ‘Gang of Four’ (GoF) design patterns book [18]. reasoning. As observed by Steimann [47], a possible explanation for the • Parametricity - Most AOP languages support implicit type- success of AOP is the conception that AOP improves both the mod- directed programming using either dictionary translation or run- ularity and the structure of code, an ultimate appeal to program- time type representations. This is known to break parametricity, a highly regarded feature of pure functional languages. • Explicit effects - There is a close (perhaps even over-represented) relationship between the concept of AOP and the use of ef- Permission to make digital or hard copies of all or part of this work for personal or fects as orthogonal concerns, which are challenging in pure classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation languages such as Haskell. on the first page. To copy otherwise, to republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Given all these issues, is it possible to find an AOP-like model WGP’09, August 30, 2009, Edinburgh, Scotland, UK. that is useful for purely functional languages, without giving up Copyright c 2009 ACM 978-1-60558-510-9/09/08. $5.00 many of the cherished properties of functional programming? Per- haps more importantly and pressingly, will the effort of finding a piece of advice is a function-like expression that executes when any solution provide a payoff by bringing attractive benefits to func- of the functions designated at the pointcut are about to execute. The tional languages? act of triggering a piece of advice during a function application is The goal of this paper is to start the ball rolling by showcas- called weaving. ing the ability of AOP to improve many idiomatic applications of Pointcuts are denoted by {pc}(arg), where pc stands for either functional programming that were previously thought to be diffi- a primitive pointcut, represented by ppc, or a composite pointcut. cult, while preserving the functional flavour of the solutions. The Pointcuts specify certain join points in the program at which advice hope is that we can raise awareness and interest in the functional is woven when program execution reaches there. Here, we focus on programming community in exploring the design space of AOP join points at function invocations. Thus a primitive pointcut, ppc, languages. We choose the language AspectFun, which will be in- specifies a function f or advice name n for the invocations that will troduced shortly, as the carrier of discussion in this paper, with the be advised. It is worth mentioning that a function pointcut may be understanding that none of the examples involved is dependent on curried (this is represented by the pattern of function application this choice. to variables), which captures executions of partially applied func- We shall state upfront that this paper is not intended to offer any tions. A primitive pointcut can also be a catch-all keyword any. definitive solution to the issues listed above. However, we do dis- When used, the corresponding advice will be triggered whenever a cuss the possibilities and trade-offs that one may face and warmly function is invoked. The pointcut within (f ) syntactically inspects invite fellow functional programming researchers to venture into whether a call occurs within the definition of the function f . this great unknown! Name-based primitive pointcuts can be composed to form com- Despite targeting the functional community generally, this pa- posite pointcuts by either adding to or subtracting from the set of per is particularly relevant to generic programming, which “is about names that are captured. As one may well expect, + is commutative making programs more adaptable by making them more general” and associative, whereas − is neither. [21], in two dimensions: (i) One of the main contributions (Sec- The argument variable arg is bound to the actual argument of tion 3) of AOP in functional programming is the improved exten- the named function call, if the pattern matching is successful, and sibility and adaptability (Section 3) (ii) Specific generic program- it may contain a type scope. A type scope introduces bounded scope ming techniques in functional languages can directly benefit from to the aspect. Specifically, when the function in the pointcut is the additional power that AOP brings in (Section 3.3). polymorphic, it only matches executions with inputs of types that In the sequel of the paper, we firstly give a brief introduction of subsume the scope. As a result, it is safe to type check the body of AspectFun (Section 2), followed by presenting in details the two the advice under the strengthened assumption that arg is of type τ. major strengths of functional AOP namely extensibility (Section 3) Advice may be executed before, after, or around a join point. and separation of concerns (Section 4). We then discuss the unique An around advice is executed in place of the indicated join point, characteristics of functional AOP and the design challenges come allowing the advised pointcut to be replaced. A special keyword with them (Section 5) before concluding. proceed may be used inside the body of around advice. It is bound to the function that represents “the rest of the computation” at 2. An Overview of AspectFun the advised pointcut. When there are multiple pieces of advice applicable to a join point, their execution follows the reversed Aspect- In this section, we introduce the functional AO language, textual order: the one declared or imported later gets executed first. Fun [52, 7] , which is the carrier of our discussion. We focus on the As both before advice and after advice can be straightforwardly Haskell-like syntax of the language and only present the semantics simulated by around advice that uses proceed, AspectFun only informally with examples.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    12 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us