15 October 2007 - 15:37Annotations used for deployment
I was reading this post from Bill Burke’s blog and I found myself shocked by the sheer number of annotations required for making a business object WS-BA compatible (if I understand well the post).
One thing that I don’t like about using annotations is that they tend to stay with the code. I think that these documentation provided by annotations should be outside of the code because in this case you are coupling your business component to an external concern: you are coupling your component to the WS specification.
What you get in Bill’s post is the first stage of annotation creep: you need to externalize your component in order to plug it into an operational environment and you do it thru an annotation. Next operational environment comes with a brand-new set of annotations. And so on…
I keep thinking that the best way to deal with all these annotations would be to sub-class the original interface and apply annotations to it. You will have quite a lot of problems: the classes which are mapped to the original interface will need to be sub-classed as well and their sub-classes mapped to the annotated interface. You will have problems when updating the original interface, you will find that you need to update all its annotated sub-interfaces. And a whole other set of problems.
You feel like you almost need to define inheritance in annotations: an interface would inherit the methods from an interface and the annotations from a different place and you would work with this new interface properly annotated for the operational environment. My opinion is that annotations, like any other type of static, hard-to-change documentation, have serious limitations when it comes to exposing a class to many, varied environments and when you are using it for documenting operational concerns. No wonder so many people prefer XML…
BTW, this post uses Bill Burke’s post only for displaying an example of annotation-creep.
Later edit: If you think about the way annotations are currently used (putting them all over your code base in order to insert a component into various frameworks) they can be thought of as some sort of cross-cutting concerns (they are cross-cutting to a certain extent). I wonder if using something like an aspect would not do a better job of expressing the various concerns that annotations are currently used for. Aspects are orthogonal to the code-base at the same time, a pretty neat thing.
Wouldn’t it make sense to WS-BA-enable your whole application by specifying a point-cut and then applying annotations against this point-cut? It would be a lot easier and it would de-couple your code-base from external concerns. I am not sure if it is doable (I could think of a solution, but it is not pretty).
I think that the way annotations are currently used is not 100% OK and that it poses some maintainability problems in the future. Putting information into annotations is partly a response to XML-creep (as Bill Burke pointed out in the comments) but it is a solution far from perfect. What we are dealing with here is the need to add some information to a component in order to plug it into a framework. Annotations, as well as XML, are not doing a good job because they address this problem (plugging the component into the framework) at the individual level, at the component level. What we really need is a mechanism that would let you plug a whole set of components into a framework easily (I suggested using point-cuts).
Later Edit 2.0: I think that adding querying capabilities at the code-base level (similar to AspectJ`s point-cut language) along with a mechanism to interpret these queries into Java would be the killer feature that Java lovers wait for. It would create a whole new way of developing: for example AOP would be implemented by joining point-cuts to an interception mechanism. A lot of the current mappings (in XML or in annotations) could be solved by defining a point-cut and then a mechanism to interpret this point cut. In the above case you would define a point-cut of your components that you want to WS-BA-enable and a mechanism for working with the components returned by this point-cut. Embedding a framework into an application would consist of creating a point-cut and then passing it to the framework in order to process it.
This would be application-level introspection and reflection and it would do away with both annotation-creep and XML-creep. I can`t dwell too much on it cause I gotta go to sleep.
Later Edit 3: In this post Bill Burke argues about using meta-annotation in order to de-couple your code-base from framework specific annotations. Adding a level of indirection between framework-specific annotations will free your application from framework-specific dependencies, this is for sure, but you will still tie your code to a representation (the representation specified by your annotations that serve as end-points for the original framework specific annotations). I am not sure that this is desired. I still think that your code-base should not be polluted by any external concerns.
It is interesting to see what will happen:
1) Will the world continue with annotation-creep and XML-creep for plugging their applications into various frameworks?
2) Will the world settle for a mid-way solution, like the meta-annotation solution suggested by Bill for the same problem?
3) Will the world try to solve this thru a different design?
4) Will the world decide that frame-work plugging is so costly that we might as well migrate to a different language/platform in order to reduce these costs?
It is all a question of supply and demand basic economics: plugging an application into a framework is currently a pretty costly operation. If the demand for this operation rises significantly (the number of times an application is plugged into a framework increases) it would make sense to make an investment (new methodology, new framework, etc…) in order to slash the costs. Either you make the investment or your language/platform becomes so costly so that it will prove cost-effective to move to a different language/platform.
10 Comments | Tags: Development, Econo-computing, Favorites
15 Oct 2007 - 16:39
And you’d rather have XML creep instead? No thanks. Annotations are type-safe, require no special IDE plug-ins for auto-completion, and if designed correctly, are autodocumenting (as well as useful in documenting the behavior of your code). I suggest that, as an exercise, you redo the annotated example with an XML-based one. Which one is more verbose. Which one takes longer to write. Which is more productive.
“No wonder so many people prefer XML…”
Which people? Even pre-annotations and JDK 5, the sheer number of XDoclet users proved that users want their metadata defined in one place.
FYI, the BA annotations are JBoss specific. WS-BA is just a web services standard. No Java bindings described.
15 Oct 2007 - 16:56
Just a thought….
One idea that might get you to the same place as annotation inheritance is meta-annotations. Take a look at what is going on in Guice and Web Beans.
15 Oct 2007 - 17:08
Sorry, one more thing about annotations over XML…
Annotated classes/interfaces can be introspected with reflection apis. XML’lized metadata does not have a built-in, common, way of finding and iterating over its bound metadata.
15 Oct 2007 - 17:10
And finally…thanks for the mental exercise on this, I think you’ve given me some material for a new blog to explore your concerns.
15 Oct 2007 - 21:16
Probably trying to express the same thing in XML was more verbose but it would have de-coupled your code from the framework into which it was inserted (in this case WS-BA).
The feeling that I have about the WS standards is that they are trying to layer themselves on top of the components that they are remoting. If this is what is required then the WS standard should be de-coupled from the component itself and annotations are actually coupling the WS to your component.
As you mentioned there is an effort in remoting an object without annotations (namely writing all that XML), but my impression is that this effort is both a necessary barrier of entry to remoting (necessary in my opinion because it would force you to remote only your coarse grained components) and a way to de-couple your component from the remoting process itself (the remoting process could take many faces: the same component could be remoted via WS for ‘enterprise’ use, via REST for access by the PHP crowd, etc…).
If you have some time please tell me what you think about this. Thanks for taking the time to read my post.
15 Oct 2007 - 21:57
If you are so concerned about decoupling, just write a delegate. its a one click in Intellij, don’t know about eclipse. Still faster than XML.
16 Oct 2007 - 13:27
Yes, the delegate is a pretty neat idea. It may need to be kept up-to-date as the underlying class changes, for example if you add new methods, but it is a solution that does its job most of the time.
16 Oct 2007 - 14:34
Unless you’re adding methods, the compiler should be able to detect any underlying class changes. No?
16 Oct 2007 - 21:50
Yeah, the compiler would detect it.
However, I still think that embedding framework-specific information in annotations has its drawbacks, please see the Later Edit portion of this post.
22 Oct 2007 - 16:26
There could be a binding layer in between to decouple things. Like what I showed with web beans. I’m not a Google Guice expert, but you should take a look at that to see how they do things.