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

67
Aspect-Oriented Programming in Academia and Industry Dean Wampler Object Mentor [email protected] 1 Friday, October 19, 2007

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

Page 2: Aspect-Oriented Programming in Academia and Industry · Implementation Technologies Generic programming C++ template metaprogramming AOP Intentional programming Generative Programming

What is AOP?

History of AOP

Academia vs. industry

Future work

2Friday, October 19, 2007

Page 3: Aspect-Oriented Programming in Academia and Industry · Implementation Technologies Generic programming C++ template metaprogramming AOP Intentional programming Generative Programming

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

Page 4: Aspect-Oriented Programming in Academia and Industry · Implementation Technologies Generic programming C++ template metaprogramming AOP Intentional programming Generative Programming

Cleanand

Simple4Friday, October 19, 2007

Page 5: Aspect-Oriented Programming in Academia and Industry · Implementation Technologies Generic programming C++ template metaprogramming AOP Intentional programming Generative Programming

But, Real Applications Need:

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

Transactions

Persistence

Security

5Friday, October 19, 2007

Page 6: Aspect-Oriented Programming in Academia and Industry · Implementation Technologies Generic programming C++ template metaprogramming AOP Intentional programming Generative Programming

Tangled

Account

Code

6Friday, October 19, 2007

Page 7: Aspect-Oriented Programming in Academia and Industry · Implementation Technologies Generic programming C++ template metaprogramming AOP Intentional programming Generative Programming

Scattered

Persistence,

Code

Transactions,Security, ...

7Friday, October 19, 2007

Page 8: Aspect-Oriented Programming in Academia and Industry · Implementation Technologies Generic programming C++ template metaprogramming AOP Intentional programming Generative Programming

Modularity

is

Compromised.

8Friday, October 19, 2007

Page 9: Aspect-Oriented Programming in Academia and Industry · Implementation Technologies Generic programming C++ template metaprogramming AOP Intentional programming Generative Programming

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

Page 10: Aspect-Oriented Programming in Academia and Industry · Implementation Technologies Generic programming C++ template metaprogramming AOP Intentional programming Generative Programming

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

Page 11: Aspect-Oriented Programming in Academia and Industry · Implementation Technologies Generic programming C++ template metaprogramming AOP Intentional programming Generative Programming

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

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

11Friday, October 19, 2007

Page 12: Aspect-Oriented Programming in Academia and Industry · Implementation Technologies Generic programming C++ template metaprogramming AOP Intentional programming Generative Programming

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

raise “…” unless user_authorized endend

12Friday, October 19, 2007

Page 13: Aspect-Oriented Programming in Academia and Industry · Implementation Technologies Generic programming C++ template metaprogramming AOP Intentional programming Generative Programming

Can’t we just use

Metaprogramming?

(when available)

13Friday, October 19, 2007

Page 14: Aspect-Oriented Programming in Academia and Industry · Implementation Technologies Generic programming C++ template metaprogramming AOP Intentional programming Generative Programming

Languages that support our paradigms yield:

Higher Productivity

Higher Quality

14Friday, October 19, 2007

Page 15: Aspect-Oriented Programming in Academia and Industry · Implementation Technologies Generic programming C++ template metaprogramming AOP Intentional programming Generative Programming

Refactoring AccountHandle “overdraft” requirements as an aspect

15Friday, October 19, 2007

Page 16: Aspect-Oriented Programming in Academia and Industry · Implementation Technologies Generic programming C++ template metaprogramming AOP Intentional programming Generative Programming

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

Page 17: Aspect-Oriented Programming in Academia and Industry · Implementation Technologies Generic programming C++ template metaprogramming AOP Intentional programming Generative Programming

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

Page 18: Aspect-Oriented Programming in Academia and Industry · Implementation Technologies Generic programming C++ template metaprogramming AOP Intentional programming Generative Programming

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

Page 19: Aspect-Oriented Programming in Academia and Industry · Implementation Technologies Generic programming C++ template metaprogramming AOP Intentional programming Generative Programming

Some HistoryA Personal Perspective

19Friday, October 19, 2007

Page 20: Aspect-Oriented Programming in Academia and Industry · Implementation Technologies Generic programming C++ template metaprogramming AOP Intentional programming Generative Programming

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

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

20Friday, October 19, 2007

Page 21: Aspect-Oriented Programming in Academia and Industry · Implementation Technologies Generic programming C++ template metaprogramming AOP Intentional programming Generative Programming

“Black Box” Problems

Limits of Object-Oriented Modularity

Need controlled access to internals

Often at the “meta-level”

21Friday, October 19, 2007

Page 22: Aspect-Oriented Programming in Academia and Industry · Implementation Technologies Generic programming C++ template metaprogramming AOP Intentional programming Generative Programming

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

Page 23: Aspect-Oriented Programming in Academia and Industry · Implementation Technologies Generic programming C++ template metaprogramming AOP Intentional programming Generative Programming

At the same time...

The Internet Bubble!!

23Friday, October 19, 2007

Page 24: Aspect-Oriented Programming in Academia and Industry · Implementation Technologies Generic programming C++ template metaprogramming AOP Intentional programming Generative Programming

Persistence

Transactions

High availability

Security

...

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

24Friday, October 19, 2007

Page 25: Aspect-Oriented Programming in Academia and Industry · Implementation Technologies Generic programming C++ template metaprogramming AOP Intentional programming Generative Programming

Common Problems Led to AspectJ

25Friday, October 19, 2007

Page 26: Aspect-Oriented Programming in Academia and Industry · Implementation Technologies Generic programming C++ template metaprogramming AOP Intentional programming Generative Programming

Xerox PARC

Extension of Java

Modularizes the cross-cutting concerns (CCC)

AspectJ

26Friday, October 19, 2007

Page 27: Aspect-Oriented Programming in Academia and Industry · Implementation Technologies Generic programming C++ template metaprogramming AOP Intentional programming Generative Programming

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

Page 28: Aspect-Oriented Programming in Academia and Industry · Implementation Technologies Generic programming C++ template metaprogramming AOP Intentional programming Generative Programming

Most web/enterprise software is statically typed

Where the pain is felt

Why Java?

28Friday, October 19, 2007

Page 29: Aspect-Oriented Programming in Academia and Industry · Implementation Technologies Generic programming C++ template metaprogramming AOP Intentional programming Generative Programming

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

Page 30: Aspect-Oriented Programming in Academia and Industry · Implementation Technologies Generic programming C++ template metaprogramming AOP Intentional programming Generative Programming

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

An Aside...

30Friday, October 19, 2007

Page 31: Aspect-Oriented Programming in Academia and Industry · Implementation Technologies Generic programming C++ template metaprogramming AOP Intentional programming Generative Programming

Generative ProgrammingCzarnecki and Eisenacker

31Friday, October 19, 2007

Page 32: Aspect-Oriented Programming in Academia and Industry · Implementation Technologies Generic programming C++ template metaprogramming AOP Intentional programming Generative Programming

Analysis and Design

Domain engineering

Feature modeling

Generative Programming

32Friday, October 19, 2007

Page 33: Aspect-Oriented Programming in Academia and Industry · Implementation Technologies Generic programming C++ template metaprogramming AOP Intentional programming Generative Programming

Implementation Technologies

Generic programming

C++ template metaprogramming

AOP

Intentional programming

Generative Programming

33Friday, October 19, 2007

Page 34: Aspect-Oriented Programming in Academia and Industry · Implementation Technologies Generic programming C++ template metaprogramming AOP Intentional programming Generative Programming

IBM Research

Morphed from “Subject-Oriented Programming”

Hyper/J

More ambitious than AspectJ

Multidimensional Separation of Concerns

34Friday, October 19, 2007

Page 35: Aspect-Oriented Programming in Academia and Industry · Implementation Technologies Generic programming C++ template metaprogramming AOP Intentional programming Generative Programming

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

Page 36: Aspect-Oriented Programming in Academia and Industry · Implementation Technologies Generic programming C++ template metaprogramming AOP Intentional programming Generative Programming

AOP pervasive in open-source Java enterprise frameworks

Spring

JBoss

Industry Landscape Today

36Friday, October 19, 2007

Page 37: Aspect-Oriented Programming in Academia and Industry · Implementation Technologies Generic programming C++ template metaprogramming AOP Intentional programming Generative Programming

Lots of .NET/CLR AOP projects

Industry adoption still “tepid”

Industry Landscape Today

37Friday, October 19, 2007

Page 38: Aspect-Oriented Programming in Academia and Industry · Implementation Technologies Generic programming C++ template metaprogramming AOP Intentional programming Generative Programming

Aspect-Oriented DesignRelearning Object-Oriented Principles

38Friday, October 19, 2007

Page 39: Aspect-Oriented Programming in Academia and Industry · Implementation Technologies Generic programming C++ template metaprogramming AOP Intentional programming Generative Programming

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

39Friday, October 19, 2007

Page 40: Aspect-Oriented Programming in Academia and Industry · Implementation Technologies Generic programming C++ template metaprogramming AOP Intentional programming Generative Programming

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

Page 41: Aspect-Oriented Programming in Academia and Industry · Implementation Technologies Generic programming C++ template metaprogramming AOP Intentional programming Generative Programming

Modules should be

open for extension,

but closed for modification

Open-Closed Principle (Meyer):

41Friday, October 19, 2007

Page 42: Aspect-Oriented Programming in Academia and Industry · Implementation Technologies Generic programming C++ template metaprogramming AOP Intentional programming Generative Programming

Persistence Aspect

after set (Account.name)

Accountname

Accountfirst_namelast_name

Version 1 Version 2

???X

42Friday, October 19, 2007

Page 43: Aspect-Oriented Programming in Academia and Industry · Implementation Technologies Generic programming C++ template metaprogramming AOP Intentional programming Generative Programming

Aspects make initial version easier,

but subsequent versions harder!

43Friday, October 19, 2007

Page 44: Aspect-Oriented Programming in Academia and Industry · Implementation Technologies Generic programming C++ template metaprogramming AOP Intentional programming Generative Programming

AOSD-Evolution

Paradox!On the Existence of the

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

Kris Gybels.44Friday, October 19, 2007

Page 45: Aspect-Oriented Programming in Academia and Industry · Implementation Technologies Generic programming C++ template metaprogramming AOP Intentional programming Generative Programming

Next Generation of Thought...

45Friday, October 19, 2007

Page 46: Aspect-Oriented Programming in Academia and Industry · Implementation Technologies Generic programming C++ template metaprogramming AOP Intentional programming Generative Programming

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

46Friday, October 19, 2007

Page 47: Aspect-Oriented Programming in Academia and Industry · Implementation Technologies Generic programming C++ template metaprogramming AOP Intentional programming Generative Programming

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

Advice: The new behavior invoked at the join point.

47Friday, October 19, 2007

Page 48: Aspect-Oriented Programming in Academia and Industry · Implementation Technologies Generic programming C++ template metaprogramming AOP Intentional programming Generative Programming

… and modules should expose pointcuts...

Pointcut: The set of “interesting” join points.

… and maybe restrict access,...

48Friday, October 19, 2007

Page 49: Aspect-Oriented Programming in Academia and Industry · Implementation Technologies Generic programming C++ template metaprogramming AOP Intentional programming Generative Programming

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

49Friday, October 19, 2007

Page 50: Aspect-Oriented Programming in Academia and Industry · Implementation Technologies Generic programming C++ template metaprogramming AOP Intentional programming Generative Programming

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

Page 51: Aspect-Oriented Programming in Academia and Industry · Implementation Technologies Generic programming C++ template metaprogramming AOP Intentional programming Generative Programming

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

51Friday, October 19, 2007

Page 52: Aspect-Oriented Programming in Academia and Industry · Implementation Technologies Generic programming C++ template metaprogramming AOP Intentional programming Generative Programming

We’re rediscoveringOO Design Principles

Using Abstractions!

52Friday, October 19, 2007

Page 53: Aspect-Oriented Programming in Academia and Industry · Implementation Technologies Generic programming C++ template metaprogramming AOP Intentional programming Generative Programming

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

Page 54: Aspect-Oriented Programming in Academia and Industry · Implementation Technologies Generic programming C++ template metaprogramming AOP Intentional programming Generative Programming

What Industry Cares About

54Friday, October 19, 2007

Page 55: Aspect-Oriented Programming in Academia and Industry · Implementation Technologies Generic programming C++ template metaprogramming AOP Intentional programming Generative Programming

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

Page 56: Aspect-Oriented Programming in Academia and Industry · Implementation Technologies Generic programming C++ template metaprogramming AOP Intentional programming Generative Programming

What Academia Cares About

56Friday, October 19, 2007

Page 57: Aspect-Oriented Programming in Academia and Industry · Implementation Technologies Generic programming C++ template metaprogramming AOP Intentional programming Generative Programming

Non-trivial, interesting problems

Theoretical rigor

Publish or perish!

But longer time lines are acceptable

Academia’s Criteria

57Friday, October 19, 2007

Page 58: Aspect-Oriented Programming in Academia and Industry · Implementation Technologies Generic programming C++ template metaprogramming AOP Intentional programming Generative Programming

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

58Friday, October 19, 2007

Page 59: Aspect-Oriented Programming in Academia and Industry · Implementation Technologies Generic programming C++ template metaprogramming AOP Intentional programming Generative Programming

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

Page 60: Aspect-Oriented Programming in Academia and Industry · Implementation Technologies Generic programming C++ template metaprogramming AOP Intentional programming Generative Programming

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

Page 61: Aspect-Oriented Programming in Academia and Industry · Implementation Technologies Generic programming C++ template metaprogramming AOP Intentional programming Generative Programming

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

Page 62: Aspect-Oriented Programming in Academia and Industry · Implementation Technologies Generic programming C++ template metaprogramming AOP Intentional programming Generative Programming

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

Page 63: Aspect-Oriented Programming in Academia and Industry · Implementation Technologies Generic programming C++ template metaprogramming AOP Intentional programming Generative Programming

Massively Large Systems

How would you build a city?

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

63Friday, October 19, 2007

Page 64: Aspect-Oriented Programming in Academia and Industry · Implementation Technologies Generic programming C++ template metaprogramming AOP Intentional programming Generative Programming

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

Page 65: Aspect-Oriented Programming in Academia and Industry · Implementation Technologies Generic programming C++ template metaprogramming AOP Intentional programming Generative Programming

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

Page 66: Aspect-Oriented Programming in Academia and Industry · Implementation Technologies Generic programming C++ template metaprogramming AOP Intentional programming Generative Programming

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

Page 67: Aspect-Oriented Programming in Academia and Industry · Implementation Technologies Generic programming C++ template metaprogramming AOP Intentional programming Generative Programming

Thank You!

[email protected]

aquarium.rubyforge.org

contract4j.org

67Friday, October 19, 2007