Aspect-Oriented Programming in Academia and Industry · Implementation Technologies Generic...

Post on 16-Oct-2020

2 views 0 download

Transcript of Aspect-Oriented Programming in Academia and Industry · Implementation Technologies Generic...

What is AOP?

History of AOP

Academia vs. industry

Future work

2Friday, October 19, 2007

class Account attr_reader :balance

def credit (amount) raise "..." unless amount >= 0 @balance += amount end

def debit (amount) raise “…” unless amount < @balance @balance -= amount endend

3Friday, October 19, 2007

Cleanand

Simple4Friday, October 19, 2007

But, Real Applications Need:

class Account attr_reader :balance def credit (amount); …; end def debit (amount); …; endend

Transactions

Persistence

Security

5Friday, October 19, 2007

Tangled

Account

Code

6Friday, October 19, 2007

Scattered

Persistence,

Code

Transactions,Security, ...

7Friday, October 19, 2007

Modularity

is

Compromised.

8Friday, October 19, 2007

We would like to say...

Before returning the Account balance, read the current balance from the persistence store.

After the Account balance changes, update the new balance in the persistence store.

Before changing the Account balance, authenticate and authorize the user.

9Friday, October 19, 2007

require ‘aquarium’class Account include Aquarium::Aspects::DSL::AspectDSL

before :attribute => :balance, :attribute_options => [:reader] do |jp, *args|

jp.context.advised_object.balance = read_from_database(…) end ...

# reopen Account

aquarium.rubyforge.org

jp: Join Point10Friday, October 19, 2007

… after_returning :attribute => :balance, :attribute_options => [:writer] do |jp, *args|

update_in_database ( jp.context.advised_object.balance,…) end ...

11Friday, October 19, 2007

… before :methods => [:credit, :debit], :attributes => [:balance] do |jp, *args|

raise “…” unless user_authorized endend

12Friday, October 19, 2007

Can’t we just use

Metaprogramming?

(when available)

13Friday, October 19, 2007

Languages that support our paradigms yield:

Higher Productivity

Higher Quality

14Friday, October 19, 2007

Refactoring AccountHandle “overdraft” requirements as an aspect

15Friday, October 19, 2007

class Account attr_reader :balance

def credit (amount) raise "..." unless amount >= 0 @balance += amount end

def debit (amount) raise “…” unless amount < @balance @balance -= amount endend

16Friday, October 19, 2007

class Account attr_reader :balance

def credit (amount) raise "..." unless amount >= 0 @balance += amount end

def debit (amount) @balance -= amount endend

17Friday, October 19, 2007

module AllowableOverdraftAccount attr_accessor :max_overdraft before :type => :Account, :method => :debit do |jp, *args| account = jp.context.advised_object if (account.balance - args[0]) < -max_overdraft raise “…” end endend

18Friday, October 19, 2007

Some HistoryA Personal Perspective

19Friday, October 19, 2007

"Open Implementation, Analysis and Design of Substrate Software"OOPSLA ’95 Tutorial

G. Kiczales, R. DeLine, A. Lee, C. Maeda

20Friday, October 19, 2007

“Black Box” Problems

Limits of Object-Oriented Modularity

Need controlled access to internals

Often at the “meta-level”

21Friday, October 19, 2007

Metaobject protocols (MOPs) and reflection

MOPs for

File system cache management

Virtual memory management tuning

Process scheduler tuning

Tutorial Reflected Work On...

22Friday, October 19, 2007

At the same time...

The Internet Bubble!!

23Friday, October 19, 2007

Persistence

Transactions

High availability

Security

...

Industry developers were feeling the pain of cross-cutting concerns (CCC)

24Friday, October 19, 2007

Common Problems Led to AspectJ

25Friday, October 19, 2007

Xerox PARC

Extension of Java

Modularizes the cross-cutting concerns (CCC)

AspectJ

26Friday, October 19, 2007

aspect AllowableOverdraftAccount { float Account.maxOverdraft; before (Account account, float amount) : execution (* Account.debit(..)) && target(account) && args(amount) { if ((account.balance - amount) < - maxOverdraft) throw new OverdraftException(...); } }}

27Friday, October 19, 2007

Most web/enterprise software is statically typed

Where the pain is felt

Why Java?

28Friday, October 19, 2007

Java’s “MOP” is insufficient for CCC

Rise of byte-code engineering tools

Configured with XML!

But sufficient as a base for AOP tools

Why Java?

29Friday, October 19, 2007

Java’s Virtual Machine (and maybe the API’s) may become more important than Java itself!

An Aside...

30Friday, October 19, 2007

Generative ProgrammingCzarnecki and Eisenacker

31Friday, October 19, 2007

Analysis and Design

Domain engineering

Feature modeling

Generative Programming

32Friday, October 19, 2007

Implementation Technologies

Generic programming

C++ template metaprogramming

AOP

Intentional programming

Generative Programming

33Friday, October 19, 2007

IBM Research

Morphed from “Subject-Oriented Programming”

Hyper/J

More ambitious than AspectJ

Multidimensional Separation of Concerns

34Friday, October 19, 2007

Symmetric AOP

Aspects as first-class citizens, like classes

Asymmetric AOP

Aspects as “adjuncts”

AspectJ’s de facto model

Multidimensional Separation of Concerns

35Friday, October 19, 2007

AOP pervasive in open-source Java enterprise frameworks

Spring

JBoss

Industry Landscape Today

36Friday, October 19, 2007

Lots of .NET/CLR AOP projects

Industry adoption still “tepid”

Industry Landscape Today

37Friday, October 19, 2007

Aspect-Oriented DesignRelearning Object-Oriented Principles

38Friday, October 19, 2007

Quantification and ObliviousnessR. Filman and D Friedman (OOPSLA 2000)

39Friday, October 19, 2007

AOP can be understood as the desire to make quantified statements about the behavior of programs, and to have these quantifications hold over programs written by oblivious programmers.

40Friday, October 19, 2007

Modules should be

open for extension,

but closed for modification

Open-Closed Principle (Meyer):

41Friday, October 19, 2007

Persistence Aspect

after set (Account.name)

Accountname

Accountfirst_namelast_name

Version 1 Version 2

???X

42Friday, October 19, 2007

Aspects make initial version easier,

but subsequent versions harder!

43Friday, October 19, 2007

AOSD-Evolution

Paradox!On the Existence of the

AOSD-Evolution Paradox. Tom Tourwé, Johan Brichau,

Kris Gybels.44Friday, October 19, 2007

Next Generation of Thought...

45Friday, October 19, 2007

Non-invasiveness vs. ObliviousnessG. Kiczales, et al.

46Friday, October 19, 2007

Modules should be aware of possible advices, without assuming specifics...

Advice: The new behavior invoked at the join point.

47Friday, October 19, 2007

… and modules should expose pointcuts...

Pointcut: The set of “interesting” join points.

… and maybe restrict access,...

48Friday, October 19, 2007

… but we should still be able to advise modules without modification.

49Friday, October 19, 2007

class Account attr_reader :balance def credit (amount) ... end def debit (amount) @balance -= amount end

STATE_CHANGE = Pointcut.new :methods => [:credit, :debit] end

aquarium.rubyforge.org

50Friday, October 19, 2007

…Aspect.new :pointcut => Account.STATE_CHANGE do | … | # Persist the change...end

51Friday, October 19, 2007

We’re rediscoveringOO Design Principles

Using Abstractions!

52Friday, October 19, 2007

Open Modules

Modular Reasoning About Advice

J. Aldrich

Cross-Cutting Programming Interfaces (XPI)

Modular Software Design with Crosscutting Interfaces

Griswold, Sullivan, et al.

For Completeness...

53Friday, October 19, 2007

What Industry Cares About

54Friday, October 19, 2007

Simple (enough) to understand and use

Strong tool support

Maintainability of long-lived software

We must get paid, ASAP!

Industry Criteria for Technology

55Friday, October 19, 2007

What Academia Cares About

56Friday, October 19, 2007

Non-trivial, interesting problems

Theoretical rigor

Publish or perish!

But longer time lines are acceptable

Academia’s Criteria

57Friday, October 19, 2007

Industry and Academia Working TogetherSome current and future growth areas for AOP

58Friday, October 19, 2007

Language-Oriented Programming

Raise the abstraction level by constructing Domain Specific Languages (DSLs)

Could hide the complexity of aspects, objects, metaprogramming, etc.

59Friday, October 19, 2007

Contrived Example:…for_types(with_pointcut(PERSISTABLE)) do |type| map_attributes_of(type) .excluding.attributes_marked(:transient) on_state_changes(:write_to_store) use_cache(:memcached)end

60Friday, October 19, 2007

What Industry Will Do...

Invent lots of little, ad hoc DSL’s

Create a “Tower of Babel” situation

Developers will struggle to learn all the DSLs of all the libraries/tools they need

61Friday, October 19, 2007

What Academia Could Do...

You understand language design, AI, etc.

Help industry understand

Globally-applicable DSL design principles

Mapping DSLs to object, aspect, … assembly code

62Friday, October 19, 2007

Massively Large Systems

How would you build a city?

How would you build a software system of the same complexity?

63Friday, October 19, 2007

What Industry Will Do...

Incremental improvements on what we already know how to do

Build systems whose complexity exceeds the capabilities of our modularity tools

Struggle to maintain these systems...

64Friday, October 19, 2007

What Academia Could Do...

Understand the unique characteristics of massive systems

Find new ways to build them in a modular, manageable way

65Friday, October 19, 2007

Don’t worry too much about industry relevance!

We need people working on longer-term problems

Instead of incremental improvements…

Focus on fundamental problems and innovation!

Some Final Thoughts

66Friday, October 19, 2007

Thank You!

dean@aspectprogramming.com

aquarium.rubyforge.org

contract4j.org

67Friday, October 19, 2007