| Author: | Mikael Jansson |
|---|---|
| Date: | 2006-02-23 |
Presenting at Chalmers, Sweden, a paper by:
Gregor Kiczales, John Lamping, Anurag Mendhakar, Chris Maeda, Cristina Lopes, Jean-Marc Loingtier and John Irwin
Xerox Palo Alto Research Center, 1997
Have you ever felt that you write the same code over and over again, but you can't really parametrize on the parameters of the problem?
If you run into a case where...
...there will be aspects!
Putting images through a list of filters:
Easily composable, just apply the next filter on the result of the current filter!
What about efficiency?
Not feasible!
Observation: Systems are generally built using two constructs
Components are properties of a system which can be encapsulated in a function or an object
Example: an image filter, a bank account or a GUI widget
Aspects are tangled throughout the system, no clean encapsulation
Example: memory access or synchronization in concurrent programming
Image processing revisited
Identify and generalize pixel operations for reuse
Identify looping constructs in use
orImages xs ys = PerPixel (\(x,y) -> x or y)
xs ys
tint xs = PerPixel (\(x, y) -> x*y)
xs (repeat 1.25)
Rewriting filters -- the weaver
Rewrite filter using new information
Add aspect code to fuse loops together
Pixel-wise horizontal loops in two filters can be fused together as one:
case type input output of
(PerPixel f xs ys, PerPixel f' xs' ys') ->
...
Image processing system developed at Xerox. Goals: memory efficiency and code maintainability.
Results: better space efficiency and worse time efficiency, but with 10 times less code!
(additionally, the paper includes an example using Java)
Measuring efficiency:
reduction in bloat due to tangling = (tangled code size - component program size) / sum of aspect program sizes
As such, anything greater than 1 is a success. Putting the the image processing system in concrete figures, we get:
(35000-756) / 352 = 98
Writing a system requires three parts:
Expose joint points in the component language for the weaver to, well, weave in the aspects.
As of writing (1997), not much real evidence of aspects being generally applicable.
If you're writing code doing a similar task for a heterogenous set of components and behaviours, consider introducing aspects to your system!
EOF.