Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The software my team works on at work is java based, and make pretty extensive use of aspects with Spring AOP. Generally, I've learned two lessons to reduce the 'what the Fuck just happened here?' problem.

First, the method being given the aspect should be annotated. @LogsArgs or @Transactional. None of this 'oh we just use an auto proxy to apply this to every method' bullshit. Tell me you're doing something.

Second, the annotation should be and to tell you exactly what it's doing with just the name. @LogRequestAndResponse. What does it do? Exactly what it says. If you can't describe the end result easily, then how will the next guy have a clue what just happened?

Whenever I've followed these, I don't regret aspects very often. When I stop following them, people get confused.



Annotating the Methods seems like an anti-AOP pattern to me. Of the comments become code and get filled with AOP stuff, it's not an different Form putting the calls into the methods themself, beside some performance improvements when running the code without annotations. But the code will be littered with stuff that should be outside of it.


It makes into a slightly different but still invaluable pattern. I'd rather have code that says what it does, but says it in the most concise way possible, than code that just has black magic running on it in the background.


It's a little different:

1) Reduce 'soft' duplication. Overhead of having many small logging calls everywhere is probably higher than we all want to admit 2) Reduce small variances. Common logging format is useful (as a baseline-- additional logging is probably also useful)

I'm not terribly familiar with AOP but the cognitive overhead IMO is reduced if you just have to act as a client to logging (via annotation) than bespoke implementations at each call site.


This is good advice. You do lose the transparency of the approach in this case, but you are otherwise stuck in a higher-order form of callback hell if you don't.

Though one wonders if they could get rid of even this if they just had some dynamic scoping.




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: