Category: Coding best practices

  • Use the ‘final’ everywhere!

    The use of the keyword ‘final’ should be the rule/best practice and the default behavior: Let’s see why: In the case of ‘simple’ types (primitives, wrappers), this is easy because we can prevent value changes. In the case of objects, we can prevent reference changes, but not to the object content. Better than nothing. In…

  • Extract a logic from collections processing

    Once again, you as a developer, get a task to simplify the below code: You can simplify a little with streams: but this is not what we want to achieve, because the logic/condition is sunk in collection processing and testing is not easy and as you see, leads to testing many cases (good client, bad…

  • Functional programming styles

    Your task as a developer is to write a code for selecting clients that have a good credit history and age is above 30 and live in NY city. You wrote a code like this: A senior programmer seeing your code: You know that programmers don’t express any emotion, so you start to think that…

  • What is the functional programming style

    What do building blocks and programming have in common? Nothing and everything. In the programming world, we have various paradigms. For simplicity, we can call them styles. One of them is functional style. The functional style is similar to building a tower from building blocks: The basic element (building block) is a function: Functions are…

  • 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,…