Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Annotations from Hell

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've been using JPA lately, with struts and spring and most of my classes have a lot of annotations. It seems every framework utilizes annotations, it's really starting
to get out of hand when all my methods have 1-5 annotions each all with hardcoded values. Ok, some frameworks allow you to use configuration xml files instead of
annotating, so is it better to use config files when possible over annotations? How do you deal with all these magic numbers in the annotation parameters?

Any ideas or suggestions welcome...

Billy
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What magic numbers?

XML vs annotations really depends on your needs. Personally, I still use XML for some things--it keeps classes leaner, more clear, and more exportable into other environments. For some things, annotations are awesome, though.
 
Billy Vandory
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

David Newton wrote:What magic numbers?

XML vs annotations really depends on your needs. Personally, I still use XML for some things--it keeps classes leaner, more clear, and more exportable into other environments. For some things, annotations are awesome, though.



I agree they are awesome, but here's an example of what i mean:



the number 1 is hardcoded, the name for the generator (im not too concerned) and I managed to use a String constant for the sequence name.
But i was hoping there would be a better way than using constants. Obviously I can't say



was just wondering what other folks are doing
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well no, CATEGORY is a string.

But in how many other places do you use those enums? It's already bound to the class name by naming convention. Without knowing more I'd wonder why you have an enum for that at all.
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic