Tag: good practice
-
Managing Business Errors in Java 21 and Spring Without Using Exceptions
I’ve been trying to get engineers to rethink how they use exceptions, urging folks to ditch the habit of using unchecked exceptions for business errors handling. The reason things are the way they are now is because, years back, people didn’t really get the difference between checked and unchecked exceptions. Besides that, back then, the…
-
REST over HTTP Cheatsheet for Web APIs
Endpoints conventions GET /orders returns all orders. The response body must contain the data as an array of orders.GET /orders/{id} returns the order with identifier {id}. The response body must contain the order data.POST /orders creates an order using the data provided in the request body. The response body must contain the newly created order…
-
A Code Review Checklist
Working in a team and doing code reviews are two of the most challenging parts of engineering jobs. Mostly that’s because teams are composed of actual people, and each of those people has a different past, a different background, a different culture, a different mindset, etc. Some people care about their work and invest time…
-
Real life Kotlin example of Delegation and Dependency Injection
Showcasing a simplified version of a real-life Kotlin application for order processing where we need to enhance functionality without touching the production code. Functional requirements Supposing the system already has the functionality for order creation, now the requirements are to implement: For simplicity, we will only log a message when saving to the database, auditing…
-
Never use the “else” branch in “when” expressions over an enum, sealed interface or sealed classes in Kotlin
When using when expressions over enum or sealed hierarchy (sealed interface or sealed class), the Kotlin compiler provides, by default, exhaustiveness checks. In other words, the compiler verifies that all possible values are handled in the when expression. Adding a new type RelaxingChair without handling the new value will result in a compilation error: The…
-
You should not look at implementation to find out what the code does
Shall you check the implementation to find out what some code does? The answer is NO, even though there are some exceptions. Designing APIs is not easy and requires years of practice to do it well. Why is it not a good idea to rely on looking at implementation? Here are some reasons: When we…
-
When and how to use extension functions
Technology has evolved like never before in the past two decades. It grows so much and so fast that we can hardly keep up with it. Look at how some older people struggle to understand new technology. For such people, technology brought a mess just by removing the buttons or the rotary dialer from phones…
-
Learn the Single Responsibility Principle! Now!
So far, all projects I’ve seen have broken the Single Responsibility Principle (SRP). All of them! At some point, it becomes unavoidable, but I’m not talking about those cases. Instead, I’m referring to the ones where people have a choice and pick the simplest one without even giving it a thought. If you don’t know,…
-
Do not trust others’ data
Our world works by exchanging data. Thousands of bits flow in front of our eyes every second without us even realizing it. A touch of a screen or changes in our blood pressure or heart rate will quickly become ones and zeros and immediately travel to the other side of our planet to be stashed…
-
How to organize your code to save hours of work and write better code
Organizing your code might not seem an essential task at first. People don’t give it enough attention and the effects can become overwhelming when the project’s complexity grows. Over the years, I have encountered many projects with various structures. At some point, things always became messy. I guess it had much to do with the…