Isn't it boring to write crosscutting concerns?

To make sure we have clean code and make it easy for us to maintain, we should try to be lazy and reuse code as much as possible, we should also avoid redundant code. But when it comes to crosscutting concerns, we have to be redundant, or? What code is mostly redundant in our code? I will assume that code to check security and logging exceptions are the most redundant code we write. A method should only do one thing, but we can't skip crosscutting concerns, we need it. So basically several method will do more than one thing. Wouldn't it be much better if we only focus on the core concern and skip the crosscutting concerns when we write our code? How can we skip the crosscutting concerns but still has it? The answer is Aspect Oriented Programming (AOP). The PAG team has a Policy Injection Application BLock (PIAB) which we can use to intercept our crosscutting concerns into our code, we also have Spring.Net and some other frameworks. By using AOP frameworks we don't need to write the same code for logging exception etc over and over again, we will also have a much cleaner code, and our focus will only be the core concern. Oh, I feel so lazy, but why should I spend time to write code that do the same thing over and over again, it's so boring, isn't it :P Are you tired of writing crosscutting concerns over and over again, and do you use AOP today?
Published Thursday, December 04, 2008 7:59 AM by Fredrik N
Filed under: ,

Comments

# re: Isn't it boring to write crosscutting concerns?

Thursday, December 04, 2008 5:01 AM by Mikael Deurell

Yay! I just saw a guy with an ugly looking shirt talking about this in a very weird language... He seems to love using PIAB handlers with Unity Interception Extensions... :-)

channel9.msdn.com/.../Test-och-debuggning-med-Visual-Studio-2008-del-1-2

# re: Isn't it boring to write crosscutting concerns?

Thursday, December 04, 2008 6:01 AM by svdeursen

I must say that I hardly ever write code for logging exceptions throughout my code base. 99% of the time I let the exceptions bubble up and have a catch all mechanism on top of the (web) application that logs the unhandled exceptions.

Is this a good time to plug my own logging framework? Yes it is :-). CuttingEdge.Logging enables such a catch-all mechanism: www.codeplex.com/logging.

I must admit that never use AOP frameworks. I hardly need it for logging and for security I use the Roles and Membership Provider Model of ASP.NET. There is however a build in AOP security mechanism in .NET that I use often. The PrincipalPermissionAttribute. This attribute enables code access security on a user and role basis.

Next to that, while I consider AOP frameworks valuable, they add a layer of complexity. Most of the teams I work with, are less experienced and advising them to go with AOP, wouldn’t be a wise thing, I believe. I think it would be better if they spend time reading McConell’s Code Complete 2nd Edition, for instance, instead of using that time on mastering AOP.

# re: Isn't it boring to write crosscutting concerns?

Thursday, December 04, 2008 7:28 AM by Torkel

The problem with AOP is that it is not well supported or integrated into the CLR or .NET framework / toolset. Sure there are great AOP frameworks that solve the problem via dynamic proxies, but such solutions have some big restrictions (only virtual functions, need to instantiate the object via a proxy creator). PostSharp solves this via being a framework and a .NET post compiler (injects your crosscutting concerns and rebuilds your assemblies), the post compile step is kind of slow, otherwise PostSharp is very powerful!

www.codinginstinct.com/.../crosscutting-concerns-aop.html

I was kind of disappointed that Microsoft didn't present any plan to make AOP scenarios easier / more natural on the .NET platform

# re: Isn't it boring to write crosscutting concerns?

Thursday, December 04, 2008 8:20 AM by Jonathan

Great post!  Which framework do you currently use to help with injecting your aspects?

# re: Isn't it boring to write crosscutting concerns?

Thursday, December 04, 2008 12:12 PM by Fredrik N

@Mikael Deurell:

hi dude, I only had to write about this after our great meeting ;)

@Torkel:

I agree!

@Jonathan:

Springt.Net, but I start to like Unity together with PIAB.

# re: Isn't it boring to write crosscutting concerns?

Thursday, December 04, 2008 3:40 PM by Roger Alsing

I posted this comment on Torkels blog first but ill throw it in here too:

This is my view on this matter:

rogeralsing.com/.../code-mangling-aop-vs-runtime-proxy-aop

I can not see why on earth people would want AOP to break the most fundamental OOP rules.

Eg, if you are only allowed to change the behaviour of virtual methods via OOP.

Then why should you be allowed to do so using AOP?

AOP needs to conform to the OOP rules or we will end up with all sorts of problems.

Just my 2 cents atleast..

# re: Isn't it boring to write crosscutting concerns?

Thursday, December 04, 2008 3:45 PM by Roger Alsing

Just to clarify my point of view:

Everyone that thinks that code mangling AOP is a good idea needs to take a basic course on OOP.

That, or stop doing .NET and switch to Ruby ;-)

# AOP vs. OOP Ignorance « Roger Alsing Weblog

Friday, December 05, 2008 4:20 AM by AOP vs. OOP Ignorance « Roger Alsing Weblog

Pingback from  AOP vs. OOP Ignorance « Roger Alsing Weblog

Leave a Comment

(required) 
(required) 
(optional)
(required)