views:

283

answers:

5

My project is slowly implementing Java annotations. Half of the developers - myself included - find that doing anything complex with annotations seems to add to our overall maintenance burden. The other half of the team thinks they're the bee's knees.

What's your real-world experience with teams of developers being able to maintain annotated code?

+6  A: 

My personal experience is that, on average, dealing with annotations is far easier for most developers than dealing with your standard Java XML Configuration hell. For things like JPA and Spring testing they are absolute life-savers.

The good thing about annotations is that they make configuration on your classes self-documenting. Now, instead of having to search through a huge XML file to try and figure out how a framework is using your class, your class tells you.

Usually the issue with changes like this is that getting used to them simply takes time. Most people, including developers, resist change. I remember when I started working with Spring. For the first few weeks I wondered why anyone would put up with the headaches associated with it. Then, a few weeks later, I wondered how I'd ever lived without it.

rtperson
+4  A: 

I feel it breaks into two uses of annotations - annotations to provide a 'description' of a class vs. annotations to provide a 'dependency' of the class.

I'm fine with a 'description' use of annotations on the class - that's something that belongs on the class and the annotation helps to make a shorthand version of that - JPA annotations fall under this.

However, I don't really like the 'dependency' annotations - if you're putting the dependency directly on the class - even if it's determined at runtime from an annotation rather than at compile time in the class - isn't that breaking dependency injection? (perhaps in spirit rather than in rule...)

It may be personal preference, but I like the one big XML file that contains all the dependency information of my application - I view this as 'application configuration' rather than 'class configuration'. I'd rather search through the one known location than searching through all the classes in the app.

Nate
A: 

I absolutely love annotations. I use them from Hibernate/JPA, Seam, JAXB....anything that I can. IMO there's nothing worse than having to open up an XML file just to find out how a class is handled.

To my eye annotations allow a class to speak for itself. Also annotations are (hopefully) part of your IDEs content assist, whereas with XML config you are usually on your own.

However, it may come down to how the XML configs and Annotations are actually used by any particular library (as most offer both), and what sort of annotation is used. I can imagine that annotations that define something that is build-specific (eg. file/url paths) may actually be easier as XML config.

Damo
A: 

It depends highly on IDE support. I feel that annotations should be kept in sync with the code via checks in the IDE, but that support for this is somewhat lacking.

E.g. the older version of IDEA would warn if you overrode a function without @Override, but wouldn't remove the @Override tag if you changed the method signature (or the superclass signature, for that matter) and broke the relation.

Without support I find them a cumbersome way to add metadata to code.

Alex Feinman
A: 

i personally feel that the the specific use case you mentioned (auto-generate web forms) is a great use case for annotations. any sort of "framework" scenario where you can write simplified code and let the framework do the heavy (often repetitive) lifting based on a few suggestions (aka annotations) is, i think, the ideal use case for annotations.

i'm curious why you don't like annotations in this situation, and what you consider to be the "maintenance burden"? (and, i'm not trying to insult your position, just understand it).

james
Not insulted at all.We used to have custom tags do all of the repetitive/error prone work for us in a JSP, so that it was very lightweight to begin with. Developers were familiar with it. It's not hard to follow, either from 10,000 feet or under the sheets. The JSP was *very* easy to follow, so if there was a problem, debugging was a snap.The new system is difficult to add onto and/or change. We also have a set of developers that are going to have trouble learning to use it. When there's a problem with the display, debugging through this involves reading code that most devs don't know
Dean J
so, it sounds to me that your problem is not with the annotations, but with the framework which is consuming the annotations. if so, then the problem would be the same whether you were using annotations, config files, or whatever.
james