News for hackers. Stuff that matters.
Re:Rating 26 years of Java changes by taftster on Saturday October 11, 2025 @05:59PM (#45553053)
And then I realize I need to change that schedule. And would like to do it without recompiling my code. Oh, and I need to allow for environment specific scheduling, weekdays on one system, weekends on others. And I need other dependencies that are environment specific.

I much prefer Spring's XML configuration from the old days. Yeah, XML sucks and all that. But still, with XML, the configuration is completely external from the application and I can manage it from /etc style layouts. Hard coding and compiling in dependency injection via annotations or other such behaviors into the class directly has caused me grief over the long term pretty much every time.

Re:Rating 26 years of Java changes by nunobrito on Saturday October 11, 2025 @06:29PM (#45553206)
The only real-world usage I see for annotations are in GSON (the @Expose) and JUnit with @Test.

Never really came across with any other real cases where it solves a pressing issue as you mention. Most times is far more convenient to do things outside the compiled code.

Re:Rating 26 years of Java changes by taftster on Saturday October 11, 2025 @10:28PM (#45554632)
Agreed. These are good examples where annotations seem like a good fit. Being able to tell a processor that a method or field is "special". Test methods, serializable hints, etc.

It's kind of like, when annotations were delivered to Java, lots of projects thought they were just the next greatest thing. I followed right along at the time, as well.

But over time, finding the value in the configuration-as-code approach to application deployment, I definitely feel that annotations have been abused for many use cases.

Re:Rating 26 years of Java changes by bdangubic on Saturday October 11, 2025 @07:42PM (#45553778)
all trivial things you are listing, every single one…
Re:Rating 26 years of Java changes by sass_muffin on Saturday October 11, 2025 @08:21PM (#45553991)
I do realize you were intending to give examples of why you don't think annotations aren't very extensible, but it is an odd example as all those things can still be achieved via annotation, since the annotations can accept values loaded from env specific properties.
Re:Rating 26 years of Java changes by vlovich123 on Saturday October 11, 2025 @10:17PM (#45554570)
> env specific properties

And then if you want to change a value at runtime you have to restart the executable?

Re:Rating 26 years of Java changes by petersellers on Saturday October 11, 2025 @10:26PM (#45554620)
Most web application servers work this way. It also works really well in practice using modern CD tools - update your configuration and perform a gradual rollout of all your application servers to reflect the updated configuration.
Re:Rating 26 years of Java changes by bdangubic on Saturday October 11, 2025 @10:51PM (#45554745)
people will argue crazy sht here on HN like changing schedule is a thing* that needs instant gratification and god forbid you have to bounce a service to read an updated configuration … :)
Re:Rating 26 years of Java changes by happymellon on Monday October 13, 2025 @02:58AM (#45565518)
I have to deal with this at work for rolling db credentials, actuator refreshes are fine for this purpose.

Would be nicer if we could handle creds like it wasn't 1992, but this does the job too.

Re:Rating 26 years of Java changes by le-mark on Saturday October 11, 2025 @08:52PM (#45554129)
Exactly this, it’s great fun to have a surface level understanding of a topic and post derisively for internet points; rather then spend the time and effort to actually learn about the subject at hand!
Re:Rating 26 years of Java changes by taftster on Saturday October 11, 2025 @10:02PM (#45554505)
I'm not digging for "internet points". Yes, superficial replacement values can be retrieved from the environment. But I guess we have to give you a more imagined or sophisticated example then to make the point to you?

How about varying implementations of a service interface. Let's say I have a Scheduler interface and I want to have multiple implementations; maybe one is CronScheduler, another is RandomScheduler, another is BlueMoonScheduler. Each of these schedulers have their own properties and configuration values. I might want to choose, per environment or deployment context, which service implementation to use.

Annotation configuration makes this (near?) impossible to dynamically wire and configure these scenarios and make them tailored to the environment or deployment scenario. Annotations are generally "static" and do not follow a configuration-as-code approach to application deployment.

An external configuration file, as offered by Spring's original (less "favored") XML style, allowed a more composable and sophisticated configuration-as-code approach. Maybe that's a negative, putting that much power into the hands of the service administrator. But as I stated originally, in my experience, having statically defined annotation driven configuration and/or dependency injection has caused more problems than it has solved.

Re:Rating 26 years of Java changes by bdangubic on Saturday October 11, 2025 @10:53PM (#45554758)
Annotation configuration makes this (near?) impossible to dynamically wire and configure these scenarios and make them tailored to the environment or deployment scenario

all of your scenarios are trivial to implement with annotations

Re:Rating 26 years of Java changes by tpmoney on Sunday October 12, 2025 @11:06PM (#45564339)
> Annotation configuration makes this (near?) impossible to dynamically wire and configure these scenarios and make them tailored to the environment or deployment scenario. Annotations are generally "static" and do not follow a configuration-as-code approach to application deployment.

Off the top of my head, you could drop a `@Profile` or `@ConditionalOnProperty` annotation on each of your different schedulers and pick them at launch time simply by adding the profile you want to the arguments or the environment. That assumes you want to choose one for the whole app. If you want to have different ones in different locations, you can dynamically load beans in code. Or if you want them loaded entirely with annotations, you could define differently named beans for each context, and include `@Qualifier`s on them and in the locations they're being used.

Which isn't to say that annotations are perfect, but dynamic runtime configuration is sort of core to how spring operates, and annotations are no exception to that.

Re:Rating 26 years of Java changes by paulddraper on Saturday October 11, 2025 @08:55PM (#45554148)
So…pass that variable to your annotation.

I’m not seeing the point?

Re:Rating 26 years of Java changes by happymellon on Monday October 13, 2025 @02:54AM (#45565489)
You do know about environmental variables?