5 ms·
Annotations are a great way to get rid of boilerplate and noisy code. For instance, I find Spring @Transactional a much more effective, less bug prone and prod
by Patrol8394 3y ago
Annotations are a great way to get rid of boilerplate and noisy code.
For instance, I find Spring @Transactional a much more effective, less bug prone and productive way of dealing with db tx vs having to manual code and handle exceptions, rollback, connections etc ..
Same goes with JAX-RS.
I would choose annotations over having to code all that manually any day.
You can easily test and debug. Yes, it will cost some time to understand how aspects work and how it is all wired up, but it is worth learning.
- peanball 3y agoThe amount of times I’ve put or seen @Transactional in the wrong place where it was never called and silently ignored is pretty high. It always led to very long debugging sessions. Especially if you touch that code once a year.
- robert_dipaolo 3y agoThe problem with an annotation for that is it causes people to keep transactions open for too long. It's best practice in DB programming to keep tx's open for as short a time as possible. The longer it's open the more scope for deadlocks and contention. So we never use it in our prod code. We've put all the boiler plate code for creating the transaction, error handling, retires, etc in a helper function that takes a lambda as a param (that being the code to run in the tx). That way you can only wrap the code that needs to be in the tx, without copying and pasting all the boiler plate everywhere.
- hardware2win 3y agoTransactional is funniest shit All that magic causes weekly questions from people about how does this work or about debugging it >You can easily test and debug. As easy as putting breakpoint in actual code?
- Patrol8394 3y ago> weekly questions from people about how does this work reading the spring documentation usually help :)