Re: multi-line Strings
William Bonawentura wrote:
Consider something like this:
@Inject
@Resource( "message1" )
private String message1;
Works a treat.
I recently had occasion to work up an annotation to cover some ugly,
testable but twisted reflective code.
Writing the annotation gave multiple advantage, many quite unforeseen.
- Boilerplate code vanishes from annotated call sites.
- Leaving behind short, easy-to-comprehend routines.
- DRY - all the magic moves into one class that handles the annoation.
- Since you're in ReflectionLand anyway, you get a lot of data for logging calls.
- Orthogonal treatment - other code and tooling can use the same annotations
in novel ways with zero influence on existing consumers.
- Annotations contribute to self-documentation at least as much as boilerplate
detracts, squaring the benefit to code literacy.
- Adding modules to the system using the same annotation is super easy.
- When another programmer returned from leave, they were able to jump right
in and add another module the same day, leveraging the annotation.
JPA annotations are a good example of some of those bullet points.
Even though in this particular case I was one of the main proponents of the
annotation approach, I am still stunned at how well it worked.
Oh, that brings up another benefit. Intra-team communication around implementations
using the annotation is accelerated. It's largely because with an annotation there's
nothing to talk about once you've developed it. I had to explain the boilerplate a lot,
which is part of what led to writing the annotation. No one yet has needed an explanation
of the annotation beyond how its 'value' attribute connects it to the rest of our
lattice, and that but once.
--
Lew