-
Do not clutter production code with test code
As a developer, you are writing new functionality. The implementation is ready, but you have to write tests. To simplify the tests, you create additional helpful methods in one of the production class: Completed. Code review – comments are not allowed, removed. Merged. After some time … a problem appeared in production. The financial report…
-
Pure function
What is a pure function? What are its advantages? Why include logic in a pure function is awsome? The answers you will find in this post. The story. You, as a perfectionist developer, are wandering how to simplify the following class and testing, that is not very easy: You you feel that it could be…
-
Exploration of Repository, Service, Controller
Popular code architecture is a layered architecture. This architecture mainly consists of three layers: Spring reflects layered architecture through the concepts of @Repository, @Service, @Controller: so: Clear responsibilities @Controller should contain presentation-related logic, including data formatting, simple transformations, etc. @Service should contain business logic, and business rules. @Repository should contain data access. This may be…
-
Qualities of a good function
Methods/functions are fundamental elements from which the whole application is built. Therefore, to reach high quality software code, we need high quality functions that have these qualities: do one thing A function should do one thing. Yes, SRP also applies to methods/functions. If a function does one thing, it is simple, clear, easy to understand…
-
Good function naming
Naming is one of the most important and hardest things. Why the method names are so important? Because proper function names lower cognitive load. function name + parameters names should express what the method does If you see do you know what the function does? Not. You have to look inside!: Analyzing every function’s content…
-
What makes the code good?
Can you guess which code is better? It’s quite easy. Do you ever wonder how many curses colleagues said looking at your code? What should your code be to not makes your colleagues crazy? When you ask the “internet” ‘what is good code’ you will get many characteristics, such as readability, simplicity, consistency, maintainability, efficiency,…
-
Remove unused/dead code
You have a room full of books and you don’t even have time to read them. Every week you clean the room and have to spend a lot of time organizing and cleaning up the clutter Wouldn’t it be reasonable to throw away things you don’t use so you don’t waste time on weekly cleaning?…
-
Use comments as a booster
Don’t put comments in the code – this is one of the guidelines in the projects. Is it good? Imagine you are working with legacy code and analyzing one of the functionalities. After many long hours, you are finally done. You feel tired, but happy that you know what’s going on. You want to write…
-
Pass all parameters to function
Your task is to simplify the testing of this function logic: How easy is it to test this function? Not complicated, but not trivial either. We can use mocking: As you can see, a certain amount of test code is needed. This example is simple, but imagine that you have more complex logic and classes…
-
Do not use the Service suffix
Look at the names of classes: Do you guess what these services are responsible for, what they do, what functions/methods they contain? It is hard to guess. So why do we name classes like xxxService? Because it’s easy. We have a Book entity and without thinking we create a BookService and logic related to the…