Tuesday, September 18, 2012

XML configuration is not bad


I write this post because I red more and more post or article  that promote annotations simply clamming or suggesting  that XML is bad, unusefull... It is not for me the right way to present things.

XML and annotations are complementary technics, each adresses differents problematics.  This point of view rely on work with differents frameworks or product like Spring, CDI, guice, eclipse DS (Inversion relying on OSGI waving mecanisms), Hibernate, Jaxb, Service Mix ... where one could find many xml, annotated or source configurations...

As I agree to say that annotations are usefull in some cases, I'm not agree to replace all XML configurations by annotation only on assertions like:

  • It's less XML centric; does I should think that's XML centralization is bad ???
  • You generally have one implementation per Java interface, so even if a best practise in OO is "think in inteface terms"  I am septical when I red this point. 
    • If I observes, at the end of my conception, that I have one implementation for each interface, I should ask to myself for each interface : "should I have, reasonnably,  during the product lifecycle changes here" and then I delete or not this inteface to simplify the system.
    • Justify the use of annotations because each interface bind the only one existing implementation with no source dependency  is ok for me in the case that the answer to the previous question is  : "no changes in the future". But in  the opposite case ? You should add a sort of "routing mecanism" to point the write implementation in the considered case. So it's the same thing  as writing a configuration (in java or XML) or writing  a switch / case / new ....


In fact my purpose is not to say "annotation is evil".... IT IS NOT. Annotation is an efficient paradigm.  I just want to explain why I think that XML stays a valid technical choice dependending of the context.

Let me expose a real case :
I had to install an open source product for my client. This client wanted to use his prefered RDBMS system. The problem here, is : this RDBMS is not validated with this product.... Anyway I install both, did the configuration and saw that AUTO-INCREMENT is not supported here, as the too much long association name. At this point I though ok, no problem, let have a look to the "xml mapping files" to change this... but there no... there only annotation in source code....
So I had to get the source code, make a full search to find annotations for RDBMS, make changes, compiled sources, package and redeploy....
If I could find XML centric mapping, I should do the job, changing only XML mapping file.... more secure, more efficient in my point of view...
In this case, Xml centric configuration is good... beacause in this way, you doesn't have to :

  • modify source code
  • compile
  • package

In some case it could be expensive to do that depending of system criticity, development norms and so one...
And in some case not ....

Other thing I coul read about this point :

  • Java developpers are developers not XML editors, Ok and so what ? If the context imply XML file configuration usage, you should hire a new XML editor ? 
  • xml configuration is too verbose ? Ok it is a fact but it is sometimes veru usefull to have few human readable configuration. I currently work on a system with five hundred classes and interfaces and it's nice to be have to see the whole sytem configuration with a couple of XML files opposes with "distributes (in source code) configuration" offers by annotations uses


At the end of this post my position is :
"Annotations" and "XML configuration" are both efficient and not exclusive.



No comments:

Post a Comment