4 ms·
Ok, I have a single concrete example of Spring's AOP everywhere being a questionable value proposition. If we have a look inside a class, which appears again an
by fmstephe 13y ago
Ok, I have a single concrete example of Spring's AOP everywhere being a questionable value proposition. If we have a look inside a class, which appears again and again on our overburdened stack traces, JdkDynamicAopProxy.
Whenever you call an aspected object in Spring it likely goes through an object of this type first. On line 177 we find this
// massage return value if necessary
if (retVal != null && retVal == target) {
// Special case: it returned "this".
// Note that we can't help if the target sets
// a reference to itself in another returned object.
retVal = proxy;
}
Here we can see Spring trying to work around an edge case when a proxied object returns itself from a method call. It is noted that if the method puts a reference to itself into another object and returns it the unproxied version of the object will be exposed.
It is this kind of leakiness that contributes to a sense of horror when dealing with Spring. The abstractions provided by Spring are so pervasive and invisible that this makes me very anxious. I really feel that when dealing with the large enterprise class applications, that Spring is aiming for, something direct and _very_ explicit and _visible_ would be far far better.
- chris_wot 13y agoOuch. That is nasty. Wasn't aware of that! In this case though, wouldn't a different style of AOP be more useful? Perhaps something that doesn't use a proxy but rewrites the bytecode, like CGLIB? Not sure, not experienced enough in this I'm afraid. Is it hard to work around the corner case? Interested...
- fmstephe 13y agoDifferent people have very different views on this. It seems to be something which touches at an emotional level, or just exposes the way different people think about programming. My opinion is that aspects are a mistake in general. I think that all of the situations that I have seen aspects used they have saved roughly 5 lines of boiler plate in exchange for creating an invisible layer of very fragile code which ties you hard to your Spring container. But I really like explicit code, so you would expect me not to like aspects. I do strongly think that aspects are really solving a 'not very hard' problem while exacerbating the biggest problem I have, which is not understanding the codebase. The thing I truly hate about Spring are the stacks. Good lord, I cannot find my code in that skyscraper of abstract proxied garbage. If you want a good technical reason to dislike Spring it's good to note that deep stacks place a larger burden on your garbage collector, in this instance Spring is truly a degenerate case. W.r.t. gclib I don't want my code byte weaved. Ever. I want it to do what is says on the tin. Always. I am very willing to write and read more code to do this. If too much code is becoming a problem don't turn to Spring - try removing some of your AbstractFactoryFactories first :) (tongue sort of in cheek)
- chris_wot 13y agoFair points. At least you have a reasoned argument :-)
- fmstephe 13y agoIt took me a while to build up to a well reasoned argument :) Since I work with Spring every day it brings up some strong emotions.
- mtrimpe 13y agoIf you don't like DI or AOP, then you can just code plain Java. If you like DI but not AOP, then something like Guice or plain Java and some self-discipline would probably work better for you. If you like DI and AOP, then you can let Spring get you as close to proper AOP as Java allows without weaving, or you can use the same syntax to do compile-time weaving to get a non-leaky abstraction All these are just choices to make; it seems like you're more fighting against the fact that you don't like how the 'industry' is making these 'enterprise standard' choices for you. On a technical level it's more like criticising Rails for using meta-programming everywhere, or C because it's so low-level (i.e. that's what they were designed for! If that's not what you need, don't use it!)
- twistedpair 13y agoYeps, AOP proxies are not always the silver bullet. Enter AspectJ and weaving stage right.