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.
AspectJ implements both concerns and the weaving of crosscutting concerns using extensions of Java programming language.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With