From users-admin@aspectj.org Sat Jan 26 00:21:07 2002 X-UIDL: 947ac200b8ff05d7266231a15e388ce5 Return-Path: Delivered-To: lieber@ccs.neu.edu Received: from alpha.xerox.com (alpha.Xerox.COM [13.1.64.93]) by amber.ccs.neu.edu (Postfix) with SMTP id 1440C1AA10; Sat, 26 Jan 2002 00:21:06 -0500 (EST) Received: from aspectj.org ([209.233.50.12]) by alpha.xerox.com with SMTP id <130103(1)>; Fri, 25 Jan 2002 21:20:50 PST Received: from aspectj.org (localhost [127.0.0.1]) by aspectj.org (8.11.6/linuxconf) with ESMTP id g0Q5J2e20075; Fri, 25 Jan 2002 21:19:02 -0800 Received: from alpha.xerox.com (alpha.Xerox.COM [13.1.64.93]) by aspectj.org (8.11.6/linuxconf) with SMTP id g0Q5IUe20064 for ; Fri, 25 Jan 2002 21:18:30 -0800 Received: from pedigree.cs.ubc.ca ([142.103.6.50]) by alpha.xerox.com with SMTP id <130103(2)>; Fri, 25 Jan 2002 21:19:28 PST Received: from CALVIN (root@newcastle.cs.ubc.ca [142.103.6.21]) by pedigree.cs.ubc.ca (8.11.4/8.11.4) with SMTP id g0Q5JOg07160; Fri, 25 Jan 2002 21:19:25 -0800 (PST) Message-ID: <03cd01c1a629$56248b30$b1d3000d@CALVIN> From: "Gregor Kiczales" To: "Kirby, Nathaniel" , References: <2AB6FA25D7635A409BE86A616E73D0F70B1E0C@hqemail1> Subject: Re: (OTUG) Aspect Oriented Pitfalls MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.50.4807.1700 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4807.1700 Sender: users-admin@aspectj.org Errors-To: users-admin@aspectj.org X-BeenThere: users@aspectj.org X-Mailman-Version: 2.0.5 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: List-Unsubscribe: , List-Archive: Date: Fri, 25 Jan 2002 21:21:39 PST Status: RO Content-Length: 2613 FW: (OTUG) Aspect Oriented Pitfalls >From: "Kirby, Nathaniel" >Subject: (OTUG) Aspect Oriented Pitfalls > >One of the engineers here has pointed out that AOP might be very dangerous >as encapsulation can be avoided and invariants subverted. He points out >that it is very powerful and very easy to misuse. Well I haven't yet seen a language in which you can't write bad code! But seriously, most AspectJ users find that just like when they learned OO, it takes a while to really get the hang of it. They tend to start in the usual way, by copying canonical examples and experimenting with variations on them. But users also find that rather than being dangerous, AspectJ helps them write code that is more clear and has better encapsulation -- once they understand the kind of modularity AspectJ supports. There are several good papers that talk about this (see below), but here's a basic point to keep in mind: when properly used, AspectJ makes it possible program in a modular way, something that would otherwise be spread throughout the code. Consider the following code, adapted from the AspectJ tutorial: aspect PublicErrorLogging { Log log = new Log(); pointcut publicInterface(Object o): call(public * com.xerox.*.*(..)) && target(o); after(Object o) throwing (Error e): publicInterface(o) { log.write(o, e); } } The effect of this code is to ensure that whenever any public method of an interface or class in the com.xerox package throws an error, that error is logged before being thrown to its caller. Of course in the alternative implementation a large number of methods have a try/catch around their body. The AspectJ implementation of this crosscutting concern is clearly modular, whereas the other implementation is not. As a result, if you want to change it, its easier in the AspectJ implementation. For example, if you also want to pass the name of the method, or its arguments to log.write, you only have to edit one place in the AspectJ code. This is just a short example, but I hope it shows how what happens with AOP and AspectJ is that the usual benefits of modularity are achieved for crosscutting concerns, and that leads to better code, not more dangerous code. One paper someone else just reminded me of that talks some more about this is: http://www.cs.ubc.ca/~kdvolder/Workshops/OOPSLA2001/submissions/12-nordberg.pdf __________________________________________________ AspectJ users mailing list - users@aspectj.org To be removed send mail to users-admin@aspectj.org or visit http://aspectj.org/lists