Monday, March 22, 2010

AspectJ Programming in Scala and Groovy

AspectJ is a very important and useful tool for me.

AspectJ has been very useful for me while programming in Java (programming language), and I still think it'd be useful in Groovy and Scala programming. However, some of the things that I did with AspectJ is "obsolete" with introduction of Groovy and Scala. Take a look at Java bean getter/setters: it's fun to use AspectJ to solve that problem, but the problem doesn't exist at all in Groovy and Scala. You just use native support or add i.e. @BeanProperty to Scala beans.

AspectJ can be used in Java to implement mixins... but Scala and Groovy has its own integrated way for doing mixins/traits. I saw AspectJ as an alternative programming language! And I guess I was abusing AspectJ for things not at its core goals.

I was using AspectJ for two things: micro-structural aspects (traits, etc.) and for cross-cutting concerns aka Aspect-Oriented Programming (AOP).

Now, the micro-structural aspects are what bugs me here. Traits/mixins, getter/setters, PropertyChangeListener support can be done in AspectJ, but I think it's an abuse of AOP to implement something that Java didn't have. It's not AOP, it's fixing a programming language!

You can do the above pretty easily in Scala, natively. For example, Eclipse ScalaModules enhances OSGi BundleContext with RichBundleContext.

Cross cutting concerns aka AOP is a more valid reason to use AspectJ. Things like security, logging, Data-Context-Interaction pattern, and other macro-infrastructural aspects.

I'm not sure yet how AspectJ fares with Groovy and Scala classes. I know AspectJ deals with bytecode, not Java source, so I hope AspectJ weaves Groovy/Scala classes just fine.

AspectJ aspects are also written in Java programming language, which in some way feels backwards. (come on, enhance Scala classes using Java code? Shouldn't it be the other way around?) With @AspectJ annotation style aspects, it's possible to write Groovy/Scala aspects too, though I'm not sure about its practicalness or convenience.

If you're not familiar yet with Scala I strongly recommend Programming Scala: Scalability = Functional Programming + Objects.

Do you think AOP or Scala matters for you?


Term Papers said...

I have been visiting various blogs for my term papers writing research. I have found your blog to be quite useful. Keep updating your blog with valuable information... Regards

coach factore outlet said...

Here we play with all sorts of influences - coach factory outlet of desired shapes tiffany jewelry to prioritize the tiffany and co manner in which I go about finding what I need," the coach factory outlet tells Ecouterre.More than 1,000 runners began the race.Not just in true religion jeans, but also in making sure you stay happy until the cheap jerseys rain every day. Hey, $350 is way less than those coach outlet. For those unfamiliar, the coach factory online (only the first coach factory count toward the rankings this year) in coach outlet online carry all their own alexander wang shoes for a daily water ration and michael kors outlet tent to sleep under;The coach factory outlet is yours, but coach factory outlet is to just be yourself and be coach outlet store online.The sleek ensemble came on show through sac burberry. Choose from brands like Bernardo, michael kors outlet and others.which saw everything he could to shake off that 'alexander wang bags' image, just got the treatment from the michael kors himself, marc by marc jacobs outlet department. the company was coach factory outlet online that it can really tell that you're turned on, so michael kors should definitely be saved for the bedroom.which has seen him take on projects from labels like michael kors outlet online, to things like designing boats.

polo outlet said... Burberry Outlet Air Max Shoes Coach Black Friday Coach Black Friday Coach Cyber Monday Coach Factory Coach Outlet Factory Coach Outlet USA Coach Purses Factory Coach Purses USA Coach Store Outlet Coach Purses On Sale Monster Beats Outlet Louis Vuitton Outlet Louis Vuitton Factory Marc Jacobs On Sale MCM Outlet MCM 店铺 cheap oakley sunglasses Michael Kors Outlet Michael Kors Outlet Michael Kors Factory Michael Kors Outlet Michael Kors Factory Online Coach Factory Outlet North Face Outlet Online Polo Outlet Store Ralph Lauren UK Sac Longchamp Pairs Coach Outlet Online Coach Factory Oultet Barbour Jackets Outlet Online Canada Goose Outlet Gucci Outlet Online Michael Kors Outlet Moncler Clearance Moncler Jackets Outlet Online North Clearace Outlet Polo Ralph Lauren Outlet Online Woolrich Clearance Michael Kors Factory Outlet Coach Outlet Online USA Beats by Dre Coach Purses Outlet Online Michael Kors USA

Eric Simmons said...

Great and Useful Article.

Online Java Course

Java Online Training

Java Course Online

J2EE training

online J2EE training

Best Recommended books for Spring framework

Java Interview Questions

Java Training Institutes in Chennai

Java Training in Chennai

J2EE Training in Chennai

java j2ee training institutes in chennai

Java Course in Chennai

Post a Comment

Copyright 2009 Spring vs Java EE Web Dev. Powered by Blogger Blogger Templates create by Deluxe Templates. WP by Masterplan