Hey, #java developers, what do you want me to cover in the upcoming #JavaFridayTips?
Time for #JavaFridayTips! Often people bloat code with numerous if-else-elseif-elseif when the action depends on object type or key. Guys, we need to stop it. Your cat meaws not because it has condition “if I am a cat, then I meaw, else if I am a dog, I bark”. It meaws because it’s his nature. Your cat is an instance of a polymorphic type ConstantlyEatingAndPoopingPet, and meawing behavior is baked inside. Learn polymorphism and bake related behavior inside your objects. #java #programming #oop
In #java, the principle of using meaningful names cannot be overstated. Variable, method, and class names should clearly express their intent. For instance, daysSinceCreation is more meaningful than dsc. This makes the code self-explanatory, reducing the need for comments. Also, avoid disinformation. Don’t use a variable name accountList if it’s not a list. Clean code is all about readability and simplicity. Keep it simple, keep it clean! 🧹👨‍💻 #javafridaytips #programming #cleancode
Unit testing of current time-dependent code is clumsy unless you use #java Date/Time API in a testable way. #javafridaytips #programming
While I'm working on the next #javafridaytips check out last week’s thread about business logic and domain models in case you’ve missed it 👉 https://mastodon.social/@tyarosh/110990162760287458 #java #programming
Follow #javafridaytips for new tips every week. 💪

#javafridaytips Design your models 🧵

Let's find the right place for the business logic (BL) in a #java application. A popular choice is to put everything into "Service" classes that mutate the internals of your anemic entities and save everything into the database. You can find an example on the “wrong” screenshot. This approach has a time and place, but it's not free. While initially easy, services tend to grow uncomfortably large, too complex, hard to read, test, and maintain. #programming 👇

Next week, I'll talk about the mistake many #java developers make when implementing a service layer of a three-layer architecture. Guess what it will be? Subscribe to #javafridaytips to learn a major #maintainability boost 🚀

#javafridaytips java.util.Optional argument is a huge mistake!

#java 8 introduced java.util.Optional, a type that may or may not have a value. It helps you avoid null pointer exceptions and write better code. But, some developers use it as a type for method arguments, which is wrong. Here is why: 👇 🧵

I'm considering contributing my #java expertise to the #mastodon community. I’ve built #backend for enterprise #java #applications for 🔟 years. I can explain some common mistakes, #cleancode practices, and other #softwaredevelopment topics I used to share with my teammates as a tech lead. Subscribe to #javafridaytips and join me with your tips. Let's grow together!