Nicely put, Rob.


I have to agree in the general sense. I'd even add that annotations are one of the most abused features in Java, and I often regret their introduction into the language. For every problem solved elegantly with an annotation, you'd find ten solutions made worse. Sometimes, I even miss the days where everything was turned into an XML configuration. I've seen JEE projects mixing JSF, Spring and other annotation-based data frameworks until methods accumulated ten different annotations! How does that help anyone?


Part of why I prefer Java, as a language, to other languages in the C family is that it doesn't have things like operator overriding or hidden finalizers or magic run-time type information handling. In Java, you always can tell immediately what methods are being called in a section of code. Compare with C++ or C# where a section of code might have hidden method calls that aren't apparent without a very smartly colorizing IDE. C++ is probably the most easy-to-abuse language for this reason.


But let's focus on the very specific use for annotations in the case of ServerResource: they save you from writing your own switching method. Without annotations, you would have to override a method (actually, you'd need to override several at the moment -- the non-annotated ServerResource is still a bit of a mess right now), do your own checking of variants or whatever, and from there call the appropriate method. The annotations handle that boilerplate code for you.


The rule of thumb for good annotations, as far as I'm concerned, is that you can look at the annotation and still in your mind clearly see what the boilerplate code would look like. The moment you get into magical "it just works" mechanisms, I turn into Rob. :) POJOs magically serializing themselves into databases or flying about as part of EJB transactions sounds nice until the first bug appears. And then you would give your left leg for regular, non-generic, procedural code you can look at with your own two eyes.


As it stands, ServerResource annotations are just at about the tipping point for me. There are two different modes supported in the background (negotiated and conditional) in addition to annotated vs. non-annotated, and I honestly have no clue what goes on unless I step slowly with the debugger.


Jerome, I'm sure things will get a lot clearer as we reach the 1.2 release. But, you did ask for feedback, so here it is. Java developers are a skeptical bunch. If we believed in magic, we'd be programming in Ruby. ;)


-Tal


Rob Heittman wrote:

JAX-RS = JSR 311.  JAX-RS is available as a Restlet extension.

I'll point out one elephant in the room, though: the JAX-RS extension has not yet received the same level of attention as other Restlet extensions that were developed by the core Noelios team.  Even the Restlet-GWT extension I lead was mainly ported by Jerome ... I just helped over implementation hurdles and provided concrete use cases and documentation.  Anyway.  The JAX-RS extension doesn't feel as "finished" as the core of the project, because it's not.  This probably ain't right.

Also: JAX-RS feels a lot to me like JPA.  I can mark up any old POJO with annotations that brilliantly, even miraculously generate glue for a particular paradigm (REST or relational persistence).  But, to me, either one still amounts to a very lovely, silver filigreed, impeccably wrought glue gun.

If I'm writing RESTful web services, I want a thoroughly RESTful architecture surrounding me, dammit ... which is what Restlet provides.  I want my Resources to know all about it and leverage it to the hilt.  They are where the rubber meets the road; where the underlying system is modeled in a RESTful way.

So I'm kind of like Lars here, a conscientious annotation objector  :-)  But I also think I see what Jerome is doing too -- providing annotations that aren't meant to be a generalized glue gun, but a way to straightforwardly tell Restlet things that might take a lot of boilerplate to do otherwise.  This is a neat idea.  It seems like it's not meant to be a generic "RESTify your POJO" mechanism -- which JAX-RS already is -- but a way to author Restlet Resources with less effort and perhaps even less pratfalls.  I haven't played with it enough to know whether it fills that role effectively ... I may not get a chance before it's too late to really comment.

The broader concern I have ...  well, I vainly think I see the point of the new Resource annotations because I have become a hard core Restlet developer.  Still, what does a newbie think?  It's confusing to have two slightly different annotation systems in play at once.  It looks like Restlet is taking on JAX-RS with an alternative, and the user must choose one.  The message traffic seems to reflect this confusion is already happening.  I think having a Restlet @Get("form") and a JAX-RS @GET is probably more confusion than a lot of folks can swallow.

Hibernate seems to have played it well by heavily internalizing the JPA spec, using JPA where it fits, and providing custom annotations where it doesn't.  Maybe wrapping JAX-RS in a tighter embrace and making it more core to Restlet is part of the solution.

Or, to solve the confusion, it may be as simple as modulating the annotation names.  I don't know:  @ResourceGets("form") instead of @Get("form") or such.  This would make clear that it's a Restlet thing and not an abstract standards-driven RESTful markup thing.

Anyway ... my personal preference is to leave the darned things out entirely, so perhaps I oughtn't to be operating my keyboard to comment on this.  I only like to use annotations for purely compile-time code management purposes (@ThreadSafe, @SuppressWarnings) and not really ever for functional purposes.  Pass the boilerplate and a side of fries.

- Rob

On Wed, Apr 8, 2009 at 7:35 PM, Erik Beeson <[email protected]> wrote:
Jerome was on the JSR 311 expert group but Restlet doesn't support it?

--Erik


2009/4/8 Rémi Dewitte <[email protected]>
I can see that Jérôme has already answered a great deal of my questions in this thread :)

http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=1596334

Rémi

2009/4/8 Rémi Dewitte <[email protected]>

Hello,

I struggle to get convinced to the use of annotations for resources from all I can read from various threads.

I have the feeling to lose most of the reasons to use Java. MediaTypes are strings, I find the implementation a bit tricky with reflection forced to be cached to be fast, classloaders issues. I guess there is a rule to handle annotations with class hierarchies, etc.

I totally understand that some people like annotations and the work it has triggered was a good way to get the resource API even better.

What are the benefits of using annotations with Restlet ?
Restlet annotations are a competitor of JAXRS, right ? To what extend is it better ?
Will annotations in restlet the "advertised" way of creating restlet application ?
What are the other planned uses of annotations ?

Regards,
Rémi



Reply via email to