4 ms·
My main issue with Java is all the annotation based programming. Some of these are nice and can make the easy case super easy but if you need go even slightly
by mohaine 8y ago
My main issue with Java is all the annotation based programming. Some of these are nice and can make the easy case super easy but if you need go even slightly off the easy path you seem to quickly loose all the time gained on the easy path.
i.e.
@GET(url="http://host/users/$userid" http://host/users/$userid")
public abstract User getUser(String userid)
isn't that much easier than the python requests version but much harder if you need to add a custom dynamic header to the call.
- JohnHaugeland 8y agoFactoryFactoryStrategyFactoryAgreementChainImplementationProxy
- jayd16 8y ago>custom dynamic header Its just: @RequestHeader("Header") added to the param list.
- neuronic 8y agoThe secret is that there is always another annotation...
- joneholland 8y agoHow do you add that dynamically?
- jayd16 8y agoWhat do you mean? Like, look for any header? You can just grab them all from the request context. >@Context HttpHeaders headers I'm not sure if there's some kind of regex support or anything like that. Looping through the headers seems simple enough.
- noir_lord 8y agoI actually ran into a useful case for annotations in Java the other day. Compile time dependency injection (Micronaut framework). Not something I have a use for but it's clever. https://micronaut.io/ https://micronaut.io/
- flukus 8y agoIt's not exactly a new thing though, it's always been possible in a variety of ways, from build steps to pre-processor macros. Annotations mostly just do what macros or code generators have always done.
- dangets 8y agoYep. I love data classes for the simplicity and utility but pretty soon there are more annotations than java code. In Java I prefer Immutables over Lombok but once you add Jackson annotations, customize the Immutables generated code (@Value.Immutable, @Value.Parameter, etc), add some javax.validation (@NotNull, @NotEmpty) it gets very noisy very quickly. And yet it is still better than writing mutable bean classes by hand IMHO. Switching to / mixing in Kotlin is worth it just for the data classes at this point (and you get some type-level nullability and `val` instead of `final var` to boot). https://immutables.github.io/ https://immutables.github.io/
- usrusr 8y agoI'd also prefer immutables.org over lombok, because it cleverly gets by without changing the way sourcecode is turned into bytecode. All it ever does is generate additional class files that add the boring stuff. If lombok says "we can have all this awesome stuff if we break the rules a bit", immutables.org answers "we can have almost as much of we don't".
- Rapzid 8y agoI would be nice for any language that supported annotations(TypeScript, C#, python, etc) if we could somehow annotate the same code in different files while maintaining a single source of property truth.. A combination of interfaces and class annotations for combining them could work..
- jcheng 8y agoI don't know if this is what you mean, but Aspect Oriented Programming was a hot topic for a very short period in the early 2000's, especially in the enterprise Java community. Ultimately it didn't seem to find many use cases and the buzz died down pretty quick. https://en.wikipedia.org/wiki/AspectJ https://en.wikipedia.org/wiki/AspectJ
- EmpirePhoenix 8y agoThe hype wave is gone, but if you ever saw @Secured or @Transactional, those are aspects after all.
- Tharkun 8y ago> My main issue with Java is all the annotation based programming. That seems like an easy problem to solve. Don't use annotations. Snark aside, it can be a bit of a tricky balancing act. When there are more annotations than actual code, that's a code smell in my book and something needs to change. Separating concerns usually does the trick. I'm heavy on code generation, so anything that's boring enough to benefit from oodles of annotations will probably end up getting generated based on a 2 line config file or something.
- chii 8y agowhy differentiate annotation from non-annotation code? they are both code, and they are both lines you have to maintain/debug.
- Tharkun 8y agoThat's a fair point. IMO it's easy to mix a whole array of concerns with annotations, much more so than what you'd likely do in 'normal' code. Some annotations are really compiler instructions ("don't print these warnings"), some influece the build process, some are AOP entry points, some add runtime behaviour etc, some are security related etc. I guess I like things to be simple.
- dionian 8y agowhile I agree with your point, you should have seen the garbage that annotations replaced...