A new aspect to programming?

 

Summary

Aspect Oriented Programming (AOP) is an approach that has emerged out of object-oriented programming. A look at what this concept means.

Events

Echelon 2012
June 11 and 12, 2012

University Cultural Centre, National University of Singapore

Startup Asia Jakarta 2012
June 7 and 8, 2012

12th Floor, Annex Building, Wisma Nusantara Complex, Jl. M.H. Thamrin No. 59 Jakarta 10350, Indonesia

MMA Forum Singapore
April 23-25, 2012

Grand Hyatt Singapore

There’s a small but determined group in the coding community who are only half joking when they declare that real coders write their own device drivers because doing anything else is lazy, technologically unsound, and unnecessarily risky.

At the other end of the software spectrum are advocates of new techniques like Aspect Oriented Programming (AOP), who are 100 percent serious when they say that real coders want to be as productive as possible so they can keep their jobs, be more productive and re-use code efficiently rather than re-invent the wheel every day of their working lives.

So where did AOP come from?

For many years, object orientation (OO) was the vanguard of this movement, but even OO’s idea of creating discrete pieces of code for different functions did not mean that coders were freed from re-writing some parts of an application over and over again.

Researchers at the famed Xerox Palo Alto Research Lab (PARC) were examining the limitations of OO in the early 1990s and explored the idea of new ways programming languages might help programmer productivity by easing modularisation of code. At around the same time, then PhD student Cristina Lopes and others at Northeastern University in the USA were pursuing similar thinking. Eventually, the USA’s Defense Advanced Research Projects Agency (DARPA) noticed the work, injected funding and encouraged collaboration between PARC and Northeastern, who combined to create AspectJ, a set of extensions to Java that programmers can now use to apply AOP.

AOP’s core idea is “separating the business logic in an application from the common services that support it,” according to Adam Magee, a Senior Solution Architect with Avanade, a technology integrator that specialises in Microsoft technologies.

AOP practitioners call those common services “crosscutting concerns,” as the functionality they offer cuts across the needs of many objects in an application.

“Cross-cutting concerns could be instrumentation, auditing, logging, security checks or exception handling,” says Magee, who has applied AOP to many projects. “Writing code to interface with these services can be very time consuming and it can take a lot of time for a developer to learn how to do it.” “It also distracts them from solving the business problem—which is where the value is—and diverts them to delving around inside complex operating system plumbing.”

Benefits of AOP
AOP aims to get around these problems by separating the job of writing cross-cutting concerns—also known as “aspects”—from the job of writing objects that comprise business logic, then offering structures so that an application can simply use the functions of aspects without needing to rebuild or recode anything at all.

The technique aims to save time by allowing developers to create a definition of the cross-cutting concerns an application requires to suit every object that requires it. So instead of, for example, writing a logging system for each object—a practice AOP characterises as “scattering”—AOP practitioners would suggest that during the design phase of a project, developers should define the logging requirements for every object with the application and then create a single logging tool that performs all the logging functions that will ever be required by any part of the application.

AOP’s proponents say the benefits of this approach are several. Firstly, the effort that goes into defining all of an application’s requirements for a service like logging means the services are better-defined, better-coded and emerge offering richer functionality. It also addresses problems created when code is written to perform more than one function, as changes to one function can impact the other, a problem AOP dubs “tangling”.

Secondly, making the effort to create discrete aspects allows a development team to assign an expert to the job, so that the best people for the job can exercise their skill and experience.

A third benefit is consistency. In a typical object-oriented project different coders will often start with the same code to create a service like logging, then each diverge in their individual implementations of the logging services required to support an individual object. By creating a single piece of code, AOP offers a simple route to consistency, which enhances future re-usability and eases maintenance: Instead of re-writing logging routines throughout an application AOP makes it possible to re-write just the logging aspect and have the new functionality serve the entire application.

All of these benefits reduce the number of lines of code that need to be written, saving time, controlling costs and freeing resources for more valuable activities than writing a logging program.

AOP at work
“Traditionally when you design an application you start by defining the business functions: all the things you need the application to do,” says Brad Kasell, an engagement manager for emerging technologies at IBM.

“But then there is also all the implied stuff that never gets written in the spec, so developers end up discovering that an application needs different types of logs in different places, and needs to write to them at different times.”

“AOP means they finally have an opportunity to ask how to apply plumbing across the board so you write it once to serve the whole application.”

AOP projects therefore start with developers identifying the orthogonal functions that all objects will require. As the objects are developed, coders pinpoint “crosscut points” where each object will need to call on an orthogonal function. Instead of coding a logging service into the object, programmers instead write a “point cut” which “weaves” the aspect into the object.

The result is an application comprised of objects and a separate pool of code that delivers orthogonal services, with the objects calling on the services as required.

How to code it
Putting AOP to work is relatively simple, as a multitude of tools are available.

Open source software dominates the field. AspectJ, originally designed at PARC, was turned over to the Eclipse Foundation in 2002 and is now the most popular AOP tool.

AspectJ bills itself as “a seamless aspect-oriented extension to the Java programming language” and offers new syntax to define, create and use aspects. AspectJ can be implemented in almost any programming tool. The other most common AOP tool is AspectWerkz, created by two BEA employees and released under the lesser GNU public license.

In January 2005, AspectJ and AspectWerkz agreed to combine their efforts to create a single tool that takes the best from each project.

Commercial software vendors like JBoss also offer AOP products. The company’s JBoss AOP was released in late 2004 and offers an aspect-oriented framework and a library of aspects.

In the .NET world, things are less well-developed. In January 2005 Microsoft released an Enterprise Library offering seven different “application blocks” that Avanade’s Magee says can be considered aspects and accessed using the Attributes feature of Visual Studio .Net. Loom is another project. But the approach taken by these tools is by no means unified. AspectJ’s approach is to extend Java. An opposing camp argues that language extensions are inherently cumbersome and that AOP can be implemented using XML metadata to define cross cuts and invoke objects.

Limitations?
These conflicting approaches and the fact that no major IDE vendor has made AOP a “formal” part of their tools leads many to feel that while AOP’s central ideas are powerful, it is still immature. “I believe AOP has not quite hit total mainstream programming so a lot of people aren’t sure how to put it into their everyday work,” says Michael Smith, director of technology for BEA’s Technology Office. “It is somewhere in between mainstream and leading edge.”

And while it is in this limbo, its true potential is somewhat unknown.

John Tirsen, a consultant with development mentoring company ThoughtWorks says he has used AOP in many projects, but that its idea of modularising services is not entirely new. “It’s been done before with things like CORBA interceptors,” he says. “The more contentious issue is whether it can be used for cross-cutting business logic.”

BEA’s Smith also sees untapped potential. “Down the road we can see you might want to adjust the behaviour of middleware using AOP, maybe to instruct the middleware layer to do different things at different times” in accordance with different business rules. “We are doing a lot of that work in the VM to make that happen.”

While this kind of work sounds exciting, no-one is suggesting any timetable for their delivery, implementation or widespread adoption.

Yet the AOP genie is well and truly out of the bottle.

“Six months ago no-one ever asked me about AOP,” Smith concludes. “Now you can fill AOP sessions at a conference and clients ask without me ever bringing it up,” a sure sign that whether or not you want to write your own device drivers, AOP will deserve investigation in coming months and years.

AOP tools and where to find them
Tool Origin Licence What it does Where to find it
AspectJ Eclipse Foundation Common Public License and Mozilla Public License Adds AOP to most Java tools www.aspectj.org
AspectWerkz BEA wBSD licence AOP development tool www.aspectwerkz.codehaus.org
JBoss AOP JBoss Commercial IDE www.jboss.com/products/aop
Spring Independent developers Apache version 2 A complete J2EE framework that uses AOP transparently. A .NET version is under way www.springframework.org
Microsoft enterprise library Microsoft Free Seven ready-to-use aspects that provide caching, configuration, data access, cryptography, exception handling, logging and instrumentation and security services. www.microsoft.com/patterns/
LOOM.NET Hasso - Plattner - Institute at University of Potsdam Free A runtime weaver for .Net http://www.dcl.hpi.uni-potsdam.de/research/loom/
AspectDNG Private developers BSD Licence “AspectDNG is a .NET multi-language aspect weaver. Aspects and base code may be written in any programming language.” http://sourceforge.net/projects/
aspectdng/
 

Talkback

Add your opinion

In order to post a comment, you need to be registered. (Sign In or register below)

Post your comment

ZDNet Asia Live

@EileenZDNetAsia sounds like they need to change biz models, since no one is paying for that stuff and piracy is eating their lunch.

Maybe I should play Words with Friends again. http://t.co/JQ92Bwap

RT @wenonalok: Fact: Korean music industry uses Swedish writers! #MM12

Sony to stop feature phone sales in India by Sept. Bold or foolish move? http://t.co/HfkHxaUY #li

Win Phone devs, how important is it to integrate Win Phone with Windows and Xbox Live platforms? http://t.co/Qr2YACzJ #li

Govt aid for staff training growing in importance http://t.co/C8aOMeNU http://t.co/erFSwAUB #arcavir

http://t.co/VNaUVSe1 Govt aid for staff training growing in importance: Governments' role in... http://t.co/ziZpIsyi http://t.co/wiqTBKkj

Govt aid for staff training growing in importance. http://t.co/9FftpZ9d

Sony Mobile yanks feature phones from India - ZDNet Asia: Zee NewsSony Mobile yanks feature phones from IndiaZDN... http://t.co/c9xuPaeR

RT @MarioKaestner: Mobile #CRM gives better ROI than social http://t.co/1VahI35K Gartner via @KANASoftware

Japanese e-commerce provider Rakuten expands SEA footprint with entrance into M'sia, after Thailand and Indonesia. http://t.co/Xm28UgUL #li

Panel at #mm12 say music licensing process complex, expensive, time-consuming in Asia. Is tat why the likes of iTunes isn't in this region?

@EileenZDNetAsia What makes Asia different from elsewhere?

@joonian 360 degree biz model, which requires service providers to pay in advance licensing fees before they even begin to sell the music.

Sony Mobile yanks feature phones from India - ZDNet Asia http://t.co/1mVJNGBi

The key for mobile operators is identifying the applications that are popular with subscribers on their network. They can then work partn...

6 hours ago by camcullen on Experience trumps content in apps monetization

So much as we know , MTK6575 extremely integrated frequency1GHz ARM Cortex-A9 processor, the superiority of 3G / HSPA Modem, and help the...

2 days ago by y15822137359 on 5 SaaS adoption speed bumps to avoid

I reckon your view: "CRM is strategy, not software", if a company replicating the approach uses in ERP implementation into CRM, what they...

3 days ago by wykoong on Gartner: Mobile CRM gives better ROI than social

This video will teach you about the Excel fill handle but also provide you with a workook to download... http://www.youtube.com/watch?v=...

3 days ago by TradeBrother on A quick fill handle trick for Microsoft Excel

waiting...

5 days ago by eapete on What should count in a company's market value?

Boy, you've opened a can of worms now.

Wait for the rants & raves.

5 days ago by eapete on What should count in a company's market value?

I was puzzling before this whether to replicate the success formula we executed for a financial institute, and come out with a standard s...

6 days ago by wykoong on Drop the egos, copy ideas, then innovate

Inside ZDNet Asia