Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Guice vs AspectJ

I was working with GUice some months ago and now when I return to it, I find I have to reread the Guice documentation and examples to understand what I did with my code.

However, when I look at AspectJ it is all too intuitive. It is an intuitive extension of the Java language. I feel I can sit down and write AspectJ code immediately already.

Therefore, I am tempted to abandon my pursuit of Guice and go with AspectJ. Especially the fact that Spring is generating AspectJ code.

What features of Guice are there above AspectJ that should discourage me from abandoning Guice?

Why wouldn't Google abandon Guice and use AspectJ instead?

Vice Versa, What are the features of AspectJ that would encourage me to abandon Guice, besides the intuitiveness of it?

If I may be allowed to "weave" in a question here, what is precluding Java language from being merged with AspectJ or provide similar "aspects" in a future version of Java?

Note: to trigger happy delete-azillas, I realise this question may be too general - but if I knew what further specifics to ask, then I would not even need to ask but just google/bing for what I know that I don't know. As you can see, my Guice knowledge has degraded so badly that I don't even recognise my own handwriting.

like image 497
Blessed Geek Avatar asked Aug 19 '10 20:08

Blessed Geek


People also ask

What is AspectJ used for?

AspectJ implements both concerns and the weaving of crosscutting concerns using extensions of Java programming language.

Which is better Guice or Spring?

Spring allows you to omit the @Autowired annotation when there's only one constructor. Guice allows binding to a Provider, as well as injecting a Provider of your class, even when your class has no Provider binding.

Is AspectJ slow?

No doubt about it: AspectJ won't make your programs faster. It adds an additional amount of overhead to your program. Every aspect is a piece of code that has to be executed, consuming time along the way.


2 Answers

As Peter says, Guice and AspectJ are totally different things. Guice does dependency injection, saving lots of factory writing while making code flexible and easy to test and adding useful things like scopes. It also happens to allow a very simple, easy way of doing AOP via method interception (with programmatic configuration of what methods get intercepted, rather than a DSL). This is effectively just another bonus it provides and not its core goal at all.

As far as why AspectJ isn't merged into Java... I don't feel like many people would want that to happen. AOP is powerful, but in a dangerous way. While it's certainly great for some uses and simplifies code a lot in those cases, if overused it could make it a lot harder to comprehend what happens in a program.

like image 105
ColinD Avatar answered Sep 20 '22 16:09

ColinD


According to me AspectJ and Guice do different things.

Guice injects dependencies and AspectJ deals with crosscutting concerns.

If you use spring then indeed there is less value in using Guice since there is too much overlap and then the symbiosis of Spring/AspectJ is a compelling solution.

I personqlly like guice better for non-spring projects because of its lighter weight.

like image 26
Peter Tillemans Avatar answered Sep 23 '22 16:09

Peter Tillemans